1use crate::error::UnknownDigest;
2use std::{fmt, str::FromStr};
3
4#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
6#[non_exhaustive]
7pub enum SigningAlgo {
8 #[allow(unused)]
10 Rsa,
11 EcP256,
13 EcP384,
15}
16
17impl fmt::Display for SigningAlgo {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 f.write_str(match self {
20 SigningAlgo::Rsa => "RSA PKCS#1 v1.5",
21 SigningAlgo::EcP256 => "ECDSA with NIST P-256 curve",
22 SigningAlgo::EcP384 => "ECDSA with NIST P-384 curve",
23 })
24 }
25}
26
27#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
29#[non_exhaustive]
30pub enum DigestAlgo {
31 Sha1,
33 Sha256,
35 Sha384,
37}
38
39impl fmt::Display for DigestAlgo {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 f.write_str(match self {
42 DigestAlgo::Sha1 => "SHA-1",
43 DigestAlgo::Sha256 => "SHA-256",
44 DigestAlgo::Sha384 => "SHA-384",
45 })
46 }
47}
48
49impl FromStr for DigestAlgo {
50 type Err = UnknownDigest;
51
52 fn from_str(s: &str) -> Result<Self, Self::Err> {
53 let s = s.to_ascii_lowercase();
54
55 match s.as_str() {
56 "sha1" | "sha-1" => Ok(Self::Sha1),
57 "sha256" | "sha-256" => Ok(Self::Sha256),
58 "sha384" | "sha-384" => Ok(Self::Sha384),
59 _ => Err(UnknownDigest(s.into_boxed_str())),
60 }
61 }
62}