@@ -140,12 +140,14 @@ impl Algorithm {
140140 /// - `sk-ssh-ed25519@openssh.com` (FIDO/U2F key)
141141 ///
142142 /// Any other algorithms are mapped to the [`Algorithm::Other`] variant.
143+ ///
144+ /// # Errors
145+ /// Returns [`Error::Encoding`] in the event the algorithm name is not known.
143146 pub fn new ( id : & str ) -> Result < Self > {
144147 Ok ( id. parse ( ) ?)
145148 }
146149
147- /// Decode algorithm from the given string identifier as used by
148- /// the OpenSSH certificate format.
150+ /// Decode algorithm from the given string identifier as used by the OpenSSH certificate format.
149151 ///
150152 /// OpenSSH certificate algorithms end in `*-cert-v01@openssh.com`.
151153 /// See [PROTOCOL.certkeys] for more information.
@@ -163,6 +165,9 @@ impl Algorithm {
163165 /// Any other algorithms are mapped to the [`Algorithm::Other`] variant.
164166 ///
165167 /// [PROTOCOL.certkeys]: https://cvsweb.openbsd.org/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD
168+ ///
169+ /// # Errors
170+ /// Returns [`Error::AlgorithmUnknown`] in the event the algorithm is not known.
166171 pub fn new_certificate ( id : & str ) -> Result < Self > {
167172 match id {
168173 CERT_DSA => Ok ( Algorithm :: Dsa ) ,
@@ -193,6 +198,7 @@ impl Algorithm {
193198 }
194199
195200 /// Get the string identifier which corresponds to this algorithm.
201+ #[ must_use]
196202 pub fn as_str ( & self ) -> & str {
197203 match self {
198204 Algorithm :: Dsa => SSH_DSA ,
@@ -222,6 +228,7 @@ impl Algorithm {
222228 ///
223229 /// [PROTOCOL.certkeys]: https://cvsweb.openbsd.org/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD
224230 #[ cfg( feature = "alloc" ) ]
231+ #[ must_use]
225232 pub fn to_certificate_type ( & self ) -> String {
226233 match self {
227234 Algorithm :: Dsa => CERT_DSA ,
@@ -246,21 +253,25 @@ impl Algorithm {
246253 }
247254
248255 /// Is the algorithm DSA?
256+ #[ must_use]
249257 pub fn is_dsa ( self ) -> bool {
250258 self == Algorithm :: Dsa
251259 }
252260
253261 /// Is the algorithm ECDSA?
262+ #[ must_use]
254263 pub fn is_ecdsa ( self ) -> bool {
255264 matches ! ( self , Algorithm :: Ecdsa { .. } )
256265 }
257266
258267 /// Is the algorithm Ed25519?
268+ #[ must_use]
259269 pub fn is_ed25519 ( self ) -> bool {
260270 self == Algorithm :: Ed25519
261271 }
262272
263273 /// Is the algorithm RSA?
274+ #[ must_use]
264275 pub fn is_rsa ( self ) -> bool {
265276 matches ! ( self , Algorithm :: Rsa { .. } )
266277 }
@@ -340,11 +351,15 @@ impl EcdsaCurve {
340351 /// - `nistp256`
341352 /// - `nistp384`
342353 /// - `nistp521`
354+ ///
355+ /// # Errors
356+ /// Returns [`Error::Encoding`] in the event the algorithm name is not known.
343357 pub fn new ( id : & str ) -> Result < Self > {
344358 Ok ( id. parse ( ) ?)
345359 }
346360
347361 /// Get the string identifier which corresponds to this ECDSA elliptic curve.
362+ #[ must_use]
348363 pub fn as_str ( self ) -> & ' static str {
349364 match self {
350365 EcdsaCurve :: NistP256 => "nistp256" ,
@@ -370,6 +385,12 @@ impl AsRef<str> for EcdsaCurve {
370385 }
371386}
372387
388+ impl From < EcdsaCurve > for Algorithm {
389+ fn from ( curve : EcdsaCurve ) -> Algorithm {
390+ Algorithm :: Ecdsa { curve }
391+ }
392+ }
393+
373394impl Label for EcdsaCurve { }
374395
375396impl fmt:: Display for EcdsaCurve {
@@ -410,11 +431,15 @@ impl HashAlg {
410431 ///
411432 /// - `sha256`
412433 /// - `sha512`
434+ ///
435+ /// # Errors
436+ /// Returns [`Error::Encoding`] in the event the algorithm name is not known.
413437 pub fn new ( id : & str ) -> Result < Self > {
414438 Ok ( id. parse ( ) ?)
415439 }
416440
417441 /// Get the string identifier for this hash algorithm.
442+ #[ must_use]
418443 pub fn as_str ( self ) -> & ' static str {
419444 match self {
420445 HashAlg :: Sha256 => SHA256 ,
@@ -423,6 +448,7 @@ impl HashAlg {
423448 }
424449
425450 /// Get the size of a digest produced by this hash function.
451+ #[ must_use]
426452 pub const fn digest_size ( self ) -> usize {
427453 match self {
428454 HashAlg :: Sha256 => 32 ,
@@ -432,6 +458,7 @@ impl HashAlg {
432458
433459 /// Compute a digest of the given message using this hash function.
434460 #[ cfg( feature = "alloc" ) ]
461+ #[ must_use]
435462 pub fn digest ( self , msg : & [ u8 ] ) -> Vec < u8 > {
436463 match self {
437464 HashAlg :: Sha256 => Sha256 :: digest ( msg) . to_vec ( ) ,
@@ -497,11 +524,16 @@ impl KdfAlg {
497524 ///
498525 /// # Supported KDF names
499526 /// - `none`
527+ /// - `bcrypt`
528+ ///
529+ /// # Errors
530+ /// Returns [`Error::Encoding`] in the event the algorithm name is not known.
500531 pub fn new ( kdfname : & str ) -> Result < Self > {
501532 Ok ( kdfname. parse ( ) ?)
502533 }
503534
504535 /// Get the string identifier which corresponds to this algorithm.
536+ #[ must_use]
505537 pub fn as_str ( self ) -> & ' static str {
506538 match self {
507539 Self :: None => NONE ,
@@ -510,6 +542,7 @@ impl KdfAlg {
510542 }
511543
512544 /// Is the KDF algorithm "none"?
545+ #[ must_use]
513546 pub fn is_none ( self ) -> bool {
514547 self == Self :: None
515548 }
0 commit comments