Skip to content

Commit 6d28e00

Browse files
authored
const-oid: add constructor from_bytes for ObjectIdentifier<MAX_SIZE> (#1852)
1 parent ed74dc8 commit 6d28e00

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

const-oid/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,18 @@ impl ObjectIdentifier {
119119

120120
/// Parse an OID from from its BER/DER encoding.
121121
pub fn from_bytes(ber_bytes: &[u8]) -> Result<Self> {
122-
ObjectIdentifierRef::from_bytes(ber_bytes)?.try_into()
122+
Self::from_bytes_sized(ber_bytes)
123123
}
124124
}
125125

126126
impl<const MAX_SIZE: usize> ObjectIdentifier<MAX_SIZE> {
127+
/// Parse an OID from from its BER/DER encoding.
128+
///
129+
/// Returns `Err(Error::Length)` if bytes do not fit in `MAX_SIZE`.
130+
pub fn from_bytes_sized(ber_bytes: &[u8]) -> Result<Self> {
131+
ObjectIdentifierRef::from_bytes(ber_bytes)?.try_into()
132+
}
133+
127134
/// Get the BER/DER serialization of this OID as bytes.
128135
///
129136
/// Note that this encoding omits the ASN.1 tag/length, and only contains the value portion of

0 commit comments

Comments
 (0)