@@ -25,19 +25,20 @@ pub use error::{Error, Result};
2525pub use fields:: { Field , Fields } ;
2626
2727#[ cfg( feature = "alloc" ) ]
28- pub use allocating:: McfHash ;
28+ pub use allocating:: PasswordHash ;
2929
3030/// Debug message used in panics when invariants aren't properly held.
3131const INVARIANT_MSG : & str = "should be ensured valid by constructor" ;
3232
33- /// Zero-copy decoder for hashes in the Modular Crypt Format (MCF).
33+ /// Password hash reference type for hashes encoded in the Modular Crypt Format (MCF),
34+ /// e.g. `$<id>$...`.
3435///
35- /// For more information, see [`McfHash `].
36+ /// For more information, see [`PasswordHash `].
3637#[ derive( Clone , Copy , Debug , Eq , PartialEq , PartialOrd , Ord ) ]
37- pub struct McfHashRef < ' a > ( & ' a str ) ;
38+ pub struct PasswordHashRef < ' a > ( & ' a str ) ;
3839
39- impl < ' a > McfHashRef < ' a > {
40- /// Parse the given input string, returning an [`McfHashRef `] if valid.
40+ impl < ' a > PasswordHashRef < ' a > {
41+ /// Parse the given input string, returning an [`PasswordHashRef `] if valid.
4142 pub fn new ( s : & ' a str ) -> Result < Self > {
4243 validate ( s) ?;
4344 Ok ( Self ( s) )
@@ -69,20 +70,20 @@ impl<'a> McfHashRef<'a> {
6970 }
7071}
7172
72- impl < ' a > From < McfHashRef < ' a > > for & ' a str {
73- fn from ( hash : McfHashRef < ' a > ) -> & ' a str {
73+ impl < ' a > From < PasswordHashRef < ' a > > for & ' a str {
74+ fn from ( hash : PasswordHashRef < ' a > ) -> & ' a str {
7475 hash. 0
7576 }
7677}
7778
7879#[ cfg( feature = "alloc" ) ]
79- impl From < McfHashRef < ' _ > > for alloc:: string:: String {
80- fn from ( hash : McfHashRef < ' _ > ) -> Self {
80+ impl From < PasswordHashRef < ' _ > > for alloc:: string:: String {
81+ fn from ( hash : PasswordHashRef < ' _ > ) -> Self {
8182 hash. 0 . into ( )
8283 }
8384}
8485
85- impl < ' a > TryFrom < & ' a str > for McfHashRef < ' a > {
86+ impl < ' a > TryFrom < & ' a str > for PasswordHashRef < ' a > {
8687 type Error = Error ;
8788
8889 fn try_from ( s : & ' a str ) -> Result < Self > {
@@ -92,11 +93,14 @@ impl<'a> TryFrom<&'a str> for McfHashRef<'a> {
9293
9394#[ cfg( feature = "alloc" ) ]
9495mod allocating {
95- use crate :: { Base64 , Error , Field , Fields , McfHashRef , Result , fields, validate, validate_id} ;
96+ use crate :: {
97+ Base64 , Error , Field , Fields , PasswordHashRef , Result , fields, validate, validate_id,
98+ } ;
9699 use alloc:: string:: String ;
97100 use core:: { fmt, str} ;
98101
99- /// Modular Crypt Format (MCF) serialized password hash.
102+ /// Password hash encoded in the Modular Crypt Format (MCF). Owned form with builder
103+ /// functionality.
100104 ///
101105 /// Password hashes in this format take the form `${id}$...`, where `{id}` is a short numeric or
102106 /// alphanumeric algorithm identifier optionally containing a `-`, followed by `$` as a delimiter,
@@ -111,25 +115,25 @@ mod allocating {
111115 /// $6$rounds=100000$exn6tVc2j/MZD8uG$BI1Xh8qQSK9J4m14uwy7abn.ctj/TIAzlaVCto0MQrOFIeTXsc1iwzH16XEWo/a7c7Y9eVJvufVzYAs4EsPOy0
112116 /// ```
113117 #[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord ) ]
114- pub struct McfHash ( String ) ;
118+ pub struct PasswordHash ( String ) ;
115119
116- impl McfHash {
117- /// Parse the given input string, returning an [`McfHash `] if valid.
118- pub fn new ( s : impl Into < String > ) -> Result < McfHash > {
120+ impl PasswordHash {
121+ /// Parse the given input string, returning an [`PasswordHash `] if valid.
122+ pub fn new ( s : impl Into < String > ) -> Result < PasswordHash > {
119123 let s = s. into ( ) ;
120124 validate ( & s) ?;
121125 Ok ( Self ( s) )
122126 }
123127
124- /// Create an [`McfHash `] from an identifier.
128+ /// Create an [`PasswordHash `] from an identifier.
125129 ///
126130 /// # Returns
127131 ///
128132 /// Error if the identifier is invalid.
129133 ///
130134 /// Allowed characters match the regex: `[a-z0-9\-]`, where the first and last characters do NOT
131135 /// contain a `-`.
132- pub fn from_id ( id : & str ) -> Result < McfHash > {
136+ pub fn from_id ( id : & str ) -> Result < PasswordHash > {
133137 validate_id ( id) ?;
134138
135139 // TODO(tarcieri): overestimate capacity so most password hashes fit?
@@ -144,9 +148,9 @@ mod allocating {
144148 & self . 0
145149 }
146150
147- /// Get an [`McfHashRef `] which corresponds to this owned [`McfHash `].
148- pub fn as_mcf_hash_ref ( & self ) -> McfHashRef < ' _ > {
149- McfHashRef ( self . as_str ( ) )
151+ /// Get an [`PasswordHashRef `] which corresponds to this owned [`PasswordHash `].
152+ pub fn as_mcf_hash_ref ( & self ) -> PasswordHashRef < ' _ > {
153+ PasswordHashRef ( self . as_str ( ) )
150154 }
151155
152156 /// Get the algorithm identifier for this MCF hash.
@@ -186,47 +190,47 @@ mod allocating {
186190 }
187191 }
188192
189- impl < ' a > AsRef < str > for McfHashRef < ' a > {
193+ impl < ' a > AsRef < str > for PasswordHashRef < ' a > {
190194 fn as_ref ( & self ) -> & str {
191195 self . as_str ( )
192196 }
193197 }
194198
195- impl AsRef < str > for McfHash {
199+ impl AsRef < str > for PasswordHash {
196200 fn as_ref ( & self ) -> & str {
197201 self . as_str ( )
198202 }
199203 }
200204
201- impl From < McfHash > for String {
202- fn from ( hash : McfHash ) -> Self {
205+ impl From < PasswordHash > for String {
206+ fn from ( hash : PasswordHash ) -> Self {
203207 hash. 0
204208 }
205209 }
206210
207- impl TryFrom < String > for McfHash {
211+ impl TryFrom < String > for PasswordHash {
208212 type Error = Error ;
209213
210214 fn try_from ( s : String ) -> Result < Self > {
211215 Self :: new ( s)
212216 }
213217 }
214218
215- impl TryFrom < & str > for McfHash {
219+ impl TryFrom < & str > for PasswordHash {
216220 type Error = Error ;
217221
218222 fn try_from ( s : & str ) -> Result < Self > {
219223 Self :: new ( s)
220224 }
221225 }
222226
223- impl fmt:: Display for McfHash {
227+ impl fmt:: Display for PasswordHash {
224228 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
225229 f. write_str ( self . as_str ( ) )
226230 }
227231 }
228232
229- impl str:: FromStr for McfHash {
233+ impl str:: FromStr for PasswordHash {
230234 type Err = Error ;
231235
232236 fn from_str ( s : & str ) -> Result < Self > {
0 commit comments