Skip to content

Commit 6d5c3f8

Browse files
rhashJPeterMugaas
authored andcommitted
librhash: move javadoc comments to header files
1 parent 602d2ca commit 6d5c3f8

File tree

5 files changed

+359
-259
lines changed

5 files changed

+359
-259
lines changed

librhash/rhash.c

Lines changed: 4 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
#define RHPR_FORMAT (RHPR_RAW | RHPR_HEX | RHPR_BASE32 | RHPR_BASE64)
4848
#define RHPR_MODIFIER (RHPR_UPPERCASE | RHPR_REVERSE)
4949

50-
/**
51-
* Initialize static data of rhash algorithms
52-
*/
5350
void rhash_library_init(void)
5451
{
5552
rhash_init_algorithms(RHASH_ALL_HASHES);
@@ -58,26 +55,13 @@ void rhash_library_init(void)
5855
#endif
5956
}
6057

61-
/**
62-
* Returns the number of supported hash algorithms.
63-
*
64-
* @return the number of supported hash functions
65-
*/
6658
int RHASH_API rhash_count(void)
6759
{
6860
return rhash_info_size;
6961
}
7062

71-
/* Lo-level rhash library functions */
63+
/* LOW-LEVEL LIBRHASH INTERFACE */
7264

73-
/**
74-
* Allocate and initialize RHash context for calculating hash(es).
75-
* After initializing rhash_update()/rhash_final() functions should be used.
76-
* Then the context must be freed by calling rhash_free().
77-
*
78-
* @param hash_id union of bit flags, containing ids of hashes to calculate.
79-
* @return initialized rhash context, NULL on error and errno is set
80-
*/
8165
RHASH_API rhash rhash_init(unsigned hash_id)
8266
{
8367
unsigned tail_bit_index; /* index of hash_id trailing bit */
@@ -168,11 +152,6 @@ RHASH_API rhash rhash_init(unsigned hash_id)
168152
return &rctx->rc; /* return allocated and initialized rhash context */
169153
}
170154

171-
/**
172-
* Free RHash context memory.
173-
*
174-
* @param ctx the context to free.
175-
*/
176155
void rhash_free(rhash ctx)
177156
{
178157
rhash_context_ext* const ectx = (rhash_context_ext*)ctx;
@@ -193,12 +172,6 @@ void rhash_free(rhash ctx)
193172
free(ectx);
194173
}
195174

196-
/**
197-
* Re-initialize RHash context to reuse it.
198-
* Useful to speed up processing of many small messages.
199-
*
200-
* @param ctx context to reinitialize
201-
*/
202175
RHASH_API void rhash_reset(rhash ctx)
203176
{
204177
rhash_context_ext* const ectx = (rhash_context_ext*)ctx;
@@ -221,15 +194,6 @@ RHASH_API void rhash_reset(rhash ctx)
221194
ectx->flags &= ~RCTX_FINALIZED; /* clear finalized state */
222195
}
223196

224-
/**
225-
* Calculate hashes of message.
226-
* Can be called repeatedly with chunks of the message to be hashed.
227-
*
228-
* @param ctx the rhash context
229-
* @param message message chunk
230-
* @param length length of the message chunk
231-
* @return 0 on success; On fail return -1 and set errno
232-
*/
233197
RHASH_API int rhash_update(rhash ctx, const void* message, size_t length)
234198
{
235199
rhash_context_ext* const ectx = (rhash_context_ext*)ctx;
@@ -249,13 +213,6 @@ RHASH_API int rhash_update(rhash ctx, const void* message, size_t length)
249213
return 0; /* no error processing at the moment */
250214
}
251215

252-
/**
253-
* Finalize hash calculation and optionally store the first hash.
254-
*
255-
* @param ctx the rhash context
256-
* @param first_result optional buffer to store a calculated hash with the lowest available id
257-
* @return 0 on success; On fail return -1 and set errno
258-
*/
259216
RHASH_API int rhash_final(rhash ctx, unsigned char* first_result)
260217
{
261218
unsigned i = 0;
@@ -330,34 +287,14 @@ static void rhash_put_digest(rhash ctx, unsigned hash_id, unsigned char* result)
330287
}
331288
}
332289

333-
/**
334-
* Set the callback function to be called from the
335-
* rhash_file() and rhash_file_update() functions
336-
* on processing every file block. The file block
337-
* size is set internally by rhash and now is 8 KiB.
338-
*
339-
* @param ctx rhash context
340-
* @param callback pointer to the callback function
341-
* @param callback_data pointer to data passed to the callback
342-
*/
343290
RHASH_API void rhash_set_callback(rhash ctx, rhash_callback_t callback, void* callback_data)
344291
{
345292
((rhash_context_ext*)ctx)->callback = (void*)callback;
346293
((rhash_context_ext*)ctx)->callback_data = callback_data;
347294
}
348295

296+
/* HIGH-LEVEL LIBRHASH INTERFACE */
349297

350-
/* hi-level message hashing interface */
351-
352-
/**
353-
* Compute a hash of the given message.
354-
*
355-
* @param hash_id id of hash sum to compute
356-
* @param message the message to process
357-
* @param length message length
358-
* @param result buffer to receive binary hash string
359-
* @return 0 on success, -1 on error
360-
*/
361298
RHASH_API int rhash_msg(unsigned hash_id, const void* message, size_t length, unsigned char* result)
362299
{
363300
rhash ctx;
@@ -370,17 +307,6 @@ RHASH_API int rhash_msg(unsigned hash_id, const void* message, size_t length, un
370307
return 0;
371308
}
372309

373-
/**
374-
* Hash a file or stream. Multiple hashes can be computed.
375-
* First, inintialize ctx parameter with rhash_init() before calling
376-
* rhash_file_update(). Then use rhash_final() and rhash_print()
377-
* to retrive hash values. Finaly call rhash_free() on ctx
378-
* to free allocated memory or call rhash_reset() to reuse ctx.
379-
*
380-
* @param ctx rhash context
381-
* @param fd descriptor of the file to hash
382-
* @return 0 on success, -1 on error and errno is set
383-
*/
384310
RHASH_API int rhash_file_update(rhash ctx, FILE* fd)
385311
{
386312
rhash_context_ext* const ectx = (rhash_context_ext*)ctx;
@@ -423,14 +349,6 @@ RHASH_API int rhash_file_update(rhash ctx, FILE* fd)
423349
return res;
424350
}
425351

426-
/**
427-
* Compute a single hash for given file.
428-
*
429-
* @param hash_id id of hash sum to compute
430-
* @param filepath path to the file to hash
431-
* @param result buffer to receive hash value with the lowest requested id
432-
* @return 0 on success, -1 on error and errno is set
433-
*/
434352
RHASH_API int rhash_file(unsigned hash_id, const char* filepath, unsigned char* result)
435353
{
436354
FILE* fd;
@@ -461,14 +379,6 @@ RHASH_API int rhash_file(unsigned hash_id, const char* filepath, unsigned char*
461379
#ifdef _WIN32 /* windows only function */
462380
#include <share.h>
463381

464-
/**
465-
* Compute a single hash for given file.
466-
*
467-
* @param hash_id id of hash sum to compute
468-
* @param filepath path to the file to hash
469-
* @param result buffer to receive hash value with the lowest requested id
470-
* @return 0 on success, -1 on error, -1 on error and errno is set
471-
*/
472382
RHASH_API int rhash_wfile(unsigned hash_id, const wchar_t* filepath, unsigned char* result)
473383
{
474384
FILE* fd;
@@ -514,64 +424,32 @@ const rhash_info* rhash_info_by_id(unsigned hash_id)
514424
return rhash_info_table[rhash_ctz(hash_id)].info;
515425
}
516426

517-
/**
518-
* Detect default digest output format for given hash algorithm.
519-
*
520-
* @param hash_id the id of hash algorithm
521-
* @return 1 for base32 format, 0 for hexadecimal
522-
*/
523427
RHASH_API int rhash_is_base32(unsigned hash_id)
524428
{
525429
/* fast method is just to test a bit-mask */
526430
return ((hash_id & (RHASH_TTH | RHASH_AICH)) != 0);
527431
}
528432

529-
/**
530-
* Returns size of binary digest for given hash algorithm.
531-
*
532-
* @param hash_id the id of hash algorithm
533-
* @return digest size in bytes
534-
*/
535433
RHASH_API int rhash_get_digest_size(unsigned hash_id)
536434
{
537435
hash_id &= RHASH_ALL_HASHES;
538436
if (hash_id == 0 || (hash_id & (hash_id - 1)) != 0) return -1;
539437
return (int)rhash_info_table[rhash_ctz(hash_id)].info->digest_size;
540438
}
541439

542-
/**
543-
* Returns length of digest hash string in default output format.
544-
*
545-
* @param hash_id the id of hash algorithm
546-
* @return the length of hash string
547-
*/
548440
RHASH_API int rhash_get_hash_length(unsigned hash_id)
549441
{
550442
const rhash_info* info = rhash_info_by_id(hash_id);
551443
return (int)(info ? (info->flags & F_BS32 ?
552444
BASE32_LENGTH(info->digest_size) : info->digest_size * 2) : 0);
553445
}
554446

555-
/**
556-
* Returns a name of given hash algorithm.
557-
*
558-
* @param hash_id the id of hash algorithm
559-
* @return algorithm name
560-
*/
561447
RHASH_API const char* rhash_get_name(unsigned hash_id)
562448
{
563449
const rhash_info* info = rhash_info_by_id(hash_id);
564450
return (info ? info->name : 0);
565451
}
566452

567-
/**
568-
* Returns a name part of magnet urn of the given hash algorithm.
569-
* Such magnet_name is used to generate a magnet link of the form
570-
* urn:&lt;magnet_name&gt;=&lt;hash_value&gt;.
571-
*
572-
* @param hash_id the id of hash algorithm
573-
* @return name
574-
*/
575453
RHASH_API const char* rhash_get_magnet_name(unsigned hash_id)
576454
{
577455
const rhash_info* info = rhash_info_by_id(hash_id);
@@ -617,20 +495,6 @@ static size_t rhash_get_magnet_url_size(const char* filepath,
617495
return size;
618496
}
619497

620-
/**
621-
* Print magnet link with given filepath and calculated hash sums into the
622-
* output buffer. The hash_mask can limit which hash values will be printed.
623-
* The function returns the size of the required buffer.
624-
* If output is NULL the .
625-
*
626-
* @param output a string buffer to receive the magnet link or NULL
627-
* @param filepath the file path to be printed or NULL
628-
* @param context algorithms state
629-
* @param hash_mask bit mask of the hash sums to add to the link
630-
* @param flags can be combination of bits RHPR_UPPERCASE, RHPR_NO_MAGNET,
631-
* RHPR_FILESIZE
632-
* @return number of written characters, including terminating '\0' on success, 0 on fail
633-
*/
634498
RHASH_API size_t rhash_print_magnet(char* output, const char* filepath,
635499
rhash context, unsigned hash_mask, int flags)
636500
{
@@ -689,19 +553,9 @@ RHASH_API size_t rhash_print_magnet(char* output, const char* filepath,
689553
return (output - begin);
690554
}
691555

692-
/* hash sum output */
693556

694-
/**
695-
* Print a text presentation of a given hash sum to the specified buffer,
696-
*
697-
* @param output a buffer to print the hash to
698-
* @param bytes a hash sum to print
699-
* @param size a size of hash sum in bytes
700-
* @param flags a bit-mask controlling how to format the hash sum,
701-
* can be a mix of the flags: RHPR_RAW, RHPR_HEX, RHPR_BASE32,
702-
* RHPR_BASE64, RHPR_UPPERCASE, RHPR_REVERSE
703-
* @return the number of written characters
704-
*/
557+
/* HASH SUM OUTPUT INTERFACE */
558+
705559
size_t rhash_print_bytes(char* output, const unsigned char* bytes,
706560
size_t size, int flags)
707561
{
@@ -730,21 +584,6 @@ size_t rhash_print_bytes(char* output, const unsigned char* bytes,
730584
return str_len;
731585
}
732586

733-
/**
734-
* Print text presentation of a hash sum with given hash_id to the specified
735-
* output buffer. If the hash_id is zero, then print the hash sum with
736-
* the lowest id stored in the hash context.
737-
* The function call fails if the context doesn't include a hash with the
738-
* given hash_id.
739-
*
740-
* @param output a buffer to print the hash to
741-
* @param context algorithms state
742-
* @param hash_id id of the hash sum to print or 0 to print the first hash
743-
* saved in the context.
744-
* @param flags a bitmask controlling how to print the hash. Can contain flags
745-
* RHPR_UPPERCASE, RHPR_HEX, RHPR_BASE32, RHPR_BASE64, etc.
746-
* @return the number of written characters on success or 0 on fail
747-
*/
748587
size_t RHASH_API rhash_print(char* output, rhash context, unsigned hash_id, int flags)
749588
{
750589
const rhash_info* info;
@@ -858,15 +697,6 @@ static rhash_uptr_t process_bt_msg(unsigned msg_id, torrent_ctx* bt, rhash_uptr_
858697

859698
#define PVOID2UPTR(p) ((rhash_uptr_t)(((char*)(p)) + 0))
860699

861-
/**
862-
* Process a rhash message.
863-
*
864-
* @param msg_id message identifier
865-
* @param dst message destination (can be NULL for generic messages)
866-
* @param ldata data depending on message
867-
* @param rdata data depending on message
868-
* @return message-specific data
869-
*/
870700
RHASH_API rhash_uptr_t rhash_transmit(unsigned msg_id, void* dst, rhash_uptr_t ldata, rhash_uptr_t rdata)
871701
{
872702
/* for messages working with rhash context */

0 commit comments

Comments
 (0)