[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gc_hash_buffer
From: |
Simon Josefsson |
Subject: |
Re: gc_hash_buffer |
Date: |
Wed, 12 Oct 2005 13:56:10 +0200 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> Simon Josefsson wrote:
>> > If all valid values for HASH are
>> > part of this enum type, you could write the argument as 'Gc_hash hash'
>> > instead of 'int hash'. This would be clearer.
>>
>> Yup, I have made this change. Thanks!
>
> And what about the return type? Are all possible return values listed in
> the enum Gc_rc? If so, you can change the return type of gc_hash_buffer
> to Gc_rc.
Yes. The same apply to other functions too. I installed the patch
below. Thanks!
Index: ChangeLog
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/ChangeLog,v
retrieving revision 1.1008
diff -u -p -r1.1008 ChangeLog
--- ChangeLog 12 Oct 2005 09:28:48 -0000 1.1008
+++ ChangeLog 12 Oct 2005 11:55:01 -0000
@@ -1,5 +1,10 @@
2005-10-12 Simon Josefsson <address@hidden>
+ * gc.h, gc-gnulib.c, gc-libgcrypt.c: Use Gc_rc for return types,
+ suggested by Bruno Haible <address@hidden>.
+
+2005-10-12 Simon Josefsson <address@hidden>
+
* gc-libgcrypt.c (gc_hmac_sha1): New function.
* gc-gnulib.c (gc_hmac_sha1): New function.
Index: gc.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gc.h,v
retrieving revision 1.6
diff -u -p -r1.6 gc.h
--- gc.h 12 Oct 2005 01:42:55 -0000 1.6
+++ gc.h 12 Oct 2005 11:55:01 -0000
@@ -50,7 +50,7 @@ typedef enum Gc_hash Gc_hash;
#define GC_SHA1_DIGEST_SIZE 20
/* Call before respectively after any other functions. */
-extern int gc_init (void);
+extern Gc_rc gc_init (void);
extern void gc_done (void);
/* Memory allocation (avoid). */
@@ -72,18 +72,18 @@ extern void gc_set_allocators (gc_malloc
GC_<HASH>_DIGEST_SIZE. For example, for GC_MD5 the output buffer
must be 16 bytes. The return value is 0 (GC_OK) on success, or
another Gc_rc error code. */
-extern int
+extern Gc_rc
gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *out);
/* One-call interface. */
-extern int gc_md5 (const void *in, size_t inlen, void *resbuf);
-extern int gc_sha1 (const void *in, size_t inlen, void *resbuf);
-extern int gc_hmac_md5 (const void *key, size_t keylen,
- const void *in, size_t inlen,
- char *resbuf);
-extern int gc_hmac_sha1 (const void *key, size_t keylen,
- const void *in, size_t inlen,
- char *resbuf);
+extern Gc_rc gc_md5 (const void *in, size_t inlen, void *resbuf);
+extern Gc_rc gc_sha1 (const void *in, size_t inlen, void *resbuf);
+extern Gc_rc gc_hmac_md5 (const void *key, size_t keylen,
+ const void *in, size_t inlen,
+ char *resbuf);
+extern Gc_rc gc_hmac_sha1 (const void *key, size_t keylen,
+ const void *in, size_t inlen,
+ char *resbuf);
/*
TODO:
Index: gc-gnulib.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gc-gnulib.c,v
retrieving revision 1.6
diff -u -p -r1.6 gc-gnulib.c
--- gc-gnulib.c 12 Oct 2005 09:28:48 -0000 1.6
+++ gc-gnulib.c 12 Oct 2005 11:55:01 -0000
@@ -47,10 +47,10 @@
# include "hmac.h"
#endif
-int
+Gc_rc
gc_init (void)
{
- return 0;
+ return GC_OK;
}
void
@@ -61,7 +61,7 @@ gc_done (void)
/* Randomness. */
-static int
+static Gc_rc
randomize (int level, char *data, size_t datalen)
{
int fd;
@@ -113,19 +113,19 @@ randomize (int level, char *data, size_t
return GC_OK;
}
-int
+Gc_rc
gc_nonce (char *data, size_t datalen)
{
return randomize (0, data, datalen);
}
-int
+Gc_rc
gc_pseudo_random (char *data, size_t datalen)
{
return randomize (1, data, datalen);
}
-int
+Gc_rc
gc_random (char *data, size_t datalen)
{
return randomize (2, data, datalen);
@@ -144,7 +144,7 @@ gc_set_allocators (gc_malloc_t func_mall
/* Hashes. */
-int
+Gc_rc
gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
{
switch (hash)
@@ -169,39 +169,39 @@ gc_hash_buffer (Gc_hash hash, const void
}
#ifdef GC_USE_MD5
-int
+Gc_rc
gc_md5 (const void *in, size_t inlen, void *resbuf)
{
md5_buffer (in, inlen, resbuf);
- return 0;
+ return GC_OK;
}
#endif
#ifdef GC_USE_SHA1
-int
+Gc_rc
gc_sha1 (const void *in, size_t inlen, void *resbuf)
{
sha1_buffer (in, inlen, resbuf);
- return 0;
+ return GC_OK;
}
#endif
#ifdef GC_USE_HMAC_MD5
-int
+Gc_rc
gc_hmac_md5 (const void *key, size_t keylen,
const void *in, size_t inlen, char *resbuf)
{
hmac_md5 (key, keylen, in, inlen, resbuf);
- return 0;
+ return GC_OK;
}
#endif
#ifdef GC_USE_HMAC_SHA1
-int
+Gc_rc
gc_hmac_sha1 (const void *key, size_t keylen,
const void *in, size_t inlen, char *resbuf)
{
hmac_sha1 (key, keylen, in, inlen, resbuf);
- return 0;
+ return GC_OK;
}
#endif
Index: gc-libgcrypt.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gc-libgcrypt.c,v
retrieving revision 1.6
diff -u -p -r1.6 gc-libgcrypt.c
--- gc-libgcrypt.c 12 Oct 2005 09:28:48 -0000 1.6
+++ gc-libgcrypt.c 12 Oct 2005 11:55:01 -0000
@@ -34,7 +34,7 @@
/* Initialization. */
-int
+Gc_rc
gc_init (void)
{
gcry_error_t err;
@@ -61,21 +61,21 @@ gc_done (void)
/* Randomness. */
-int
+Gc_rc
gc_nonce (char *data, size_t datalen)
{
gcry_create_nonce ((unsigned char *) data, datalen);
return GC_OK;
}
-int
+Gc_rc
gc_pseudo_random (char *data, size_t datalen)
{
gcry_randomize ((unsigned char *) data, datalen, GCRY_STRONG_RANDOM);
return GC_OK;
}
-int
+Gc_rc
gc_random (char *data, size_t datalen)
{
gcry_randomize ((unsigned char *) data, datalen, GCRY_VERY_STRONG_RANDOM);
@@ -96,7 +96,7 @@ gc_set_allocators (gc_malloc_t func_mall
/* Hashes. */
-int
+Gc_rc
gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
{
int gcryalg;
@@ -127,7 +127,7 @@ gc_hash_buffer (Gc_hash hash, const void
/* One-call interface. */
#ifdef GC_USE_MD5
-int
+Gc_rc
gc_md5 (const void *in, size_t inlen, void *resbuf)
{
size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD5);
@@ -159,7 +159,7 @@ gc_md5 (const void *in, size_t inlen, vo
#endif
#ifdef GC_USE_SHA1
-int
+Gc_rc
gc_sha1 (const void *in, size_t inlen, void *resbuf)
{
size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
@@ -191,7 +191,7 @@ gc_sha1 (const void *in, size_t inlen, v
#endif
#ifdef GC_USE_HMAC_MD5
-int
+Gc_rc
gc_hmac_md5 (const void *key, size_t keylen,
const void *in, size_t inlen, char *resbuf)
{
@@ -231,7 +231,7 @@ gc_hmac_md5 (const void *key, size_t key
#endif
#ifdef GC_USE_HMAC_SHA1
-int
+Gc_rc
gc_hmac_sha1 (const void *key, size_t keylen,
const void *in, size_t inlen, char *resbuf)
{