-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support OCTET STRING in declarativ notation #11
- Loading branch information
1 parent
72c7e72
commit 6ae4163
Showing
6 changed files
with
100 additions
and
1 deletion.
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::syn::{ReadableType, Reader, WritableType, Writer}; | ||
use core::marker::PhantomData; | ||
|
||
pub struct OctetString<C: Constraint = NoConstraint>(PhantomData<C>); | ||
|
||
impl<C: Constraint> Default for OctetString<C> { | ||
fn default() -> Self { | ||
Self(Default::default()) | ||
} | ||
} | ||
|
||
pub trait Constraint { | ||
const MIN: Option<usize> = None; | ||
const MAX: Option<usize> = None; | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct NoConstraint; | ||
impl Constraint for NoConstraint {} | ||
|
||
impl<C: Constraint> WritableType for OctetString<C> { | ||
type Type = Vec<u8>; | ||
|
||
#[inline] | ||
fn write_value<W: Writer>(writer: &mut W, value: &Self::Type) -> Result<(), W::Error> { | ||
writer.write_octet_string::<C>(value.as_slice()) | ||
} | ||
} | ||
|
||
impl<C: Constraint> ReadableType for OctetString<C> { | ||
type Type = Vec<u8>; | ||
|
||
#[inline] | ||
fn read_value<R: Reader>(reader: &mut R) -> Result<Self::Type, <R as Reader>::Error> { | ||
reader.read_octet_string::<C>() | ||
} | ||
} |
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