@@ -83,39 +83,51 @@ use bouncycastle_sha2 as sha2;
8383use bouncycastle_sha3 as sha3;
8484
8585/*** Defaults ***/
86+ ///
8687pub const DEFAULT_MAC_NAME : & str = HMAC_SHA256_NAME ;
88+ ///
8789pub const DEFAULT_128BIT_MAC_NAME : & str = HMAC_SHA256_NAME ;
90+ ///
8891pub const DEFAULT_256BIT_MAC_NAME : & str = HMAC_SHA256_NAME ;
8992
9093#[ allow( non_camel_case_types) ]
9194
95+ /// Wrapper object for all algorithms that impl [MAC].
9296/// MACFactory deviates from the usual AlgorithmFactory trait because MAC objects do not have a no-arg constructor;
9397/// instead they have a constructor that takes a [KeyMaterialTrait] and can return an error.
9498pub enum MACFactory {
95- // All members must impl MAC.
99+ ///
96100 HMAC_SHA224 ( hmac:: HMAC < sha2:: SHA224 > ) ,
101+ ///
97102 HMAC_SHA256 ( hmac:: HMAC < sha2:: SHA256 > ) ,
103+ ///
98104 HMAC_SHA384 ( hmac:: HMAC < sha2:: SHA384 > ) ,
105+ ///
99106 HMAC_SHA512 ( hmac:: HMAC < sha2:: SHA512 > ) ,
107+ ///
100108 HMAC_SHA3_224 ( hmac:: HMAC < sha3:: SHA3_224 > ) ,
109+ ///
101110 HMAC_SHA3_256 ( hmac:: HMAC < sha3:: SHA3_256 > ) ,
111+ ///
102112 HMAC_SHA3_384 ( hmac:: HMAC < sha3:: SHA3_384 > ) ,
113+ ///
103114 HMAC_SHA3_512 ( hmac:: HMAC < sha3:: SHA3_512 > ) ,
104115}
105116
106117impl MACFactory {
118+ /// Get the default MAC algorithm.
107119 pub fn default ( key : & impl KeyMaterialTrait ) -> Result < Self , FactoryError > {
108120 Self :: new ( DEFAULT_MAC_NAME , key)
109121 }
110-
122+ /// Get the default 128-bit MAC algorithm.
111123 pub fn default_128_bit ( key : & impl KeyMaterialTrait ) -> Result < Self , FactoryError > {
112124 Self :: new ( DEFAULT_128BIT_MAC_NAME , key)
113125 }
114-
126+ /// Get the default 256-bit MAC algorithm.
115127 pub fn default_256_bit ( key : & impl KeyMaterialTrait ) -> Result < Self , FactoryError > {
116128 Self :: new ( DEFAULT_256BIT_MAC_NAME , key)
117129 }
118-
130+ /// Get an instance of the algorithm by name.
119131 pub fn new ( alg_name : & str , key : & impl KeyMaterialTrait ) -> Result < Self , FactoryError > {
120132 match alg_name {
121133 DEFAULT => Self :: default ( key) ,
0 commit comments