@@ -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" ,
@@ -410,11 +425,15 @@ impl HashAlg {
410425 ///
411426 /// - `sha256`
412427 /// - `sha512`
428+ ///
429+ /// # Errors
430+ /// Returns [`Error::Encoding`] in the event the algorithm name is not known.
413431 pub fn new ( id : & str ) -> Result < Self > {
414432 Ok ( id. parse ( ) ?)
415433 }
416434
417435 /// Get the string identifier for this hash algorithm.
436+ #[ must_use]
418437 pub fn as_str ( self ) -> & ' static str {
419438 match self {
420439 HashAlg :: Sha256 => SHA256 ,
@@ -423,6 +442,7 @@ impl HashAlg {
423442 }
424443
425444 /// Get the size of a digest produced by this hash function.
445+ #[ must_use]
426446 pub const fn digest_size ( self ) -> usize {
427447 match self {
428448 HashAlg :: Sha256 => 32 ,
@@ -432,6 +452,7 @@ impl HashAlg {
432452
433453 /// Compute a digest of the given message using this hash function.
434454 #[ cfg( feature = "alloc" ) ]
455+ #[ must_use]
435456 pub fn digest ( self , msg : & [ u8 ] ) -> Vec < u8 > {
436457 match self {
437458 HashAlg :: Sha256 => Sha256 :: digest ( msg) . to_vec ( ) ,
@@ -497,11 +518,16 @@ impl KdfAlg {
497518 ///
498519 /// # Supported KDF names
499520 /// - `none`
521+ /// - `bcrypt`
522+ ///
523+ /// # Errors
524+ /// Returns [`Error::Encoding`] in the event the algorithm name is not known.
500525 pub fn new ( kdfname : & str ) -> Result < Self > {
501526 Ok ( kdfname. parse ( ) ?)
502527 }
503528
504529 /// Get the string identifier which corresponds to this algorithm.
530+ #[ must_use]
505531 pub fn as_str ( self ) -> & ' static str {
506532 match self {
507533 Self :: None => NONE ,
@@ -510,6 +536,7 @@ impl KdfAlg {
510536 }
511537
512538 /// Is the KDF algorithm "none"?
539+ #[ must_use]
513540 pub fn is_none ( self ) -> bool {
514541 self == Self :: None
515542 }
0 commit comments