1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use der::{
asn1::{Any, ObjectIdentifier},
DecodeValue, Decoder, EncodeValue, Encoder, FixedTag, Length, Tag,
};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum EcParameters {
NamedCurve(ObjectIdentifier),
}
impl DecodeValue<'_> for EcParameters {
fn decode_value(decoder: &mut Decoder<'_>, length: Length) -> der::Result<Self> {
ObjectIdentifier::decode_value(decoder, length).map(Self::NamedCurve)
}
}
impl EncodeValue for EcParameters {
fn value_len(&self) -> der::Result<Length> {
match self {
Self::NamedCurve(oid) => oid.value_len(),
}
}
fn encode_value(&self, encoder: &mut Encoder<'_>) -> der::Result<()> {
match self {
Self::NamedCurve(oid) => oid.encode_value(encoder),
}
}
}
impl EcParameters {
pub fn named_curve(self) -> Option<ObjectIdentifier> {
match self {
Self::NamedCurve(oid) => Some(oid),
}
}
}
impl<'a> From<&'a EcParameters> for Any<'a> {
fn from(params: &'a EcParameters) -> Any<'a> {
match params {
EcParameters::NamedCurve(oid) => oid.into(),
}
}
}
impl From<ObjectIdentifier> for EcParameters {
fn from(oid: ObjectIdentifier) -> EcParameters {
EcParameters::NamedCurve(oid)
}
}
impl FixedTag for EcParameters {
const TAG: Tag = Tag::ObjectIdentifier;
}