-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nathaniel McCallum <nathaniel@profian.com>
- Loading branch information
1 parent
f6ee1a4
commit ea00dfc
Showing
1 changed file
with
4 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,14 @@ | ||
//! Certification request information version identifier. | ||
use der::{Decodable, Decoder, Encodable, Encoder, FixedTag, Tag}; | ||
use der::Enumerated; | ||
|
||
/// Version identifier for certification request information. | ||
/// | ||
/// (RFC 2986 designates `0` as the only valid version) | ||
#[derive(Clone, Debug, Copy, PartialEq, Eq)] | ||
#[derive(Clone, Debug, Copy, PartialEq, Eq, Enumerated)] | ||
#[asn1(type = "INTEGER")] | ||
#[repr(u8)] | ||
pub enum Version { | ||
/// Denotes PKCS#8 v1 | ||
V1 = 0, | ||
} | ||
|
||
impl Decodable<'_> for Version { | ||
fn decode(decoder: &mut Decoder<'_>) -> der::Result<Self> { | ||
Version::try_from(u8::decode(decoder)?).map_err(|_| Self::TAG.value_error()) | ||
} | ||
} | ||
|
||
impl Encodable for Version { | ||
fn encoded_len(&self) -> der::Result<der::Length> { | ||
der::Length::from(1u8).for_tlv() | ||
} | ||
|
||
fn encode(&self, encoder: &mut Encoder<'_>) -> der::Result<()> { | ||
u8::from(*self).encode(encoder) | ||
} | ||
} | ||
|
||
impl From<Version> for u8 { | ||
fn from(version: Version) -> Self { | ||
version as u8 | ||
} | ||
} | ||
|
||
impl TryFrom<u8> for Version { | ||
type Error = der::Error; | ||
|
||
fn try_from(byte: u8) -> Result<Version, der::Error> { | ||
match byte { | ||
0 => Ok(Version::V1), | ||
_ => Err(Self::TAG.value_error()), | ||
} | ||
} | ||
} | ||
|
||
impl FixedTag for Version { | ||
const TAG: Tag = Tag::Integer; | ||
} |