Skip to content

Commit b4bfe5e

Browse files
committed
update comments concerning int return values
1 parent 2b544e5 commit b4bfe5e

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

Modules/hmacmodule.c

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ static const py_hmac_hinfo py_hmac_static_hinfo[] = {
574574
},
575575
};
576576

577+
/*
578+
* Check whether 'name' is a known HMAC hash function name,
579+
* storing the corresponding static information in 'info'.
580+
*
581+
* This function always succeeds and never set an exception.
582+
*/
577583
static inline bool
578584
find_hash_info_by_utf8name(hmacmodule_state *state,
579585
const char *name,
@@ -584,6 +590,20 @@ find_hash_info_by_utf8name(hmacmodule_state *state,
584590
return *info != NULL;
585591
}
586592

593+
/*
594+
* Find the corresponding HMAC hash function static information by its name.
595+
*
596+
* On error, propagate the exception, set 'info' to NULL and return -1.
597+
*
598+
* If no correspondence exists, set 'info' to NULL and return 0.
599+
* Otherwise, set 'info' to the deduced information and return 1.
600+
*
601+
* Parameters
602+
*
603+
* state The HMAC module state.
604+
* name The hash function name.
605+
* info The deduced information, if any.
606+
*/
587607
static int
588608
find_hash_info_by_name(hmacmodule_state *state,
589609
PyObject *name,
@@ -619,9 +639,10 @@ find_hash_info_by_name(hmacmodule_state *state,
619639
/*
620640
* Find the corresponding HMAC hash function static information.
621641
*
622-
* If an error occurs or if nothing can be found, this
623-
* returns -1 or 0 respectively, and sets 'info' to NULL.
624-
* Otherwise, this returns 1 and stores the result in 'info'.
642+
* On error, propagate the exception, set 'info' to NULL and return -1.
643+
*
644+
* If no correspondence exists, set 'info' to NULL and return 0.
645+
* Otherwise, set 'info' to the deduced information and return 1.
625646
*
626647
* Parameters
627648
*
@@ -644,6 +665,12 @@ find_hash_info_impl(hmacmodule_state *state,
644665
return 0;
645666
}
646667

668+
/*
669+
* Find the corresponding HMAC hash function static information.
670+
*
671+
* If nothing can be found or if an error occurred, return NULL
672+
* with an exception set. Otherwise return a non-NULL object.
673+
*/
647674
static const py_hmac_hinfo *
648675
find_hash_info(hmacmodule_state *state, PyObject *hash_info_ref)
649676
{
@@ -659,6 +686,7 @@ find_hash_info(hmacmodule_state *state, PyObject *hash_info_ref)
659686
"unsupported hash type: %R", hash_info_ref);
660687
return NULL;
661688
}
689+
assert(info != NULL);
662690
return info;
663691
}
664692

@@ -705,7 +733,7 @@ hmac_set_hinfo(hmacmodule_state *state,
705733
* and after hmac_set_hinfo() has been called, lest the behaviour is
706734
* undefined.
707735
*
708-
* Return 0 on success and -1 on failure.
736+
* Return 0 on success; otherwise, set an exception and return -1 on failure.
709737
*/
710738
static int
711739
hmac_new_initial_state(HMACObject *self, uint8_t *key, Py_ssize_t len)
@@ -734,7 +762,7 @@ hmac_new_initial_state(HMACObject *self, uint8_t *key, Py_ssize_t len)
734762
* and after hmac_set_hinfo() and hmac_new_initial_state() have been
735763
* called, lest the behaviour is undefined.
736764
*
737-
* Return 0 on success and -1 on failure.
765+
* Return 0 on success; otherwise, set an exception and return -1 on failure.
738766
*/
739767
static int
740768
hmac_feed_initial_data(HMACObject *self, uint8_t *msg, Py_ssize_t len)
@@ -857,7 +885,7 @@ hmac_copy_hinfo(HMACObject *out, const HMACObject *src)
857885
*
858886
* The internal state of 'out' must not already exist.
859887
*
860-
* Return 0 on success and -1 on failure.
888+
* Return 0 on success; otherwise, set an exception and return -1 on failure.
861889
*/
862890
static int
863891
hmac_copy_state(HMACObject *out, const HMACObject *src)
@@ -912,9 +940,8 @@ _hmac_HMAC_copy_impl(HMACObject *self, PyTypeObject *cls)
912940
* This unconditionally acquires the lock on the HMAC object.
913941
*
914942
* On DEBUG builds, each update() call is verified.
915-
* On other builds, only the last update() call is verified.
916943
*
917-
* Return 0 on success and -1 on failure.
944+
* Return 0 on success; otherwise, set an exception and return -1 on failure.
918945
*/
919946
static int
920947
hmac_update_state_with_lock(HMACObject *self, uint8_t *buf, Py_ssize_t len)
@@ -942,9 +969,8 @@ hmac_update_state_with_lock(HMACObject *self, uint8_t *buf, Py_ssize_t len)
942969
* This conditionally acquires the lock on the HMAC object.
943970
*
944971
* On DEBUG builds, each update() call is verified.
945-
* On other builds, only the last update() call is verified.
946972
*
947-
* Return 0 on success and -1 on failure.
973+
* Return 0 on success; otherwise, set an exception and return -1 on failure.
948974
*/
949975
static int
950976
hmac_update_state_cond_lock(HMACObject *self, uint8_t *buf, Py_ssize_t len)
@@ -966,7 +992,7 @@ hmac_update_state_cond_lock(HMACObject *self, uint8_t *buf, Py_ssize_t len)
966992
/*
967993
* Update the internal HMAC state with the given buffer.
968994
*
969-
* Return 0 on success and -1 on failure.
995+
* Return 0 on success; otherwise, set an exception and return -1 on failure.
970996
*/
971997
static inline int
972998
hmac_update_state(HMACObject *self, uint8_t *buf, Py_ssize_t len)

0 commit comments

Comments
 (0)