Start bringing this library into a more modern idiom.
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "simple_asn1"
|
name = "simple_asn1"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
authors = ["Adam Wick <awick@uhsure.com>"]
|
authors = ["Adam Wick <awick@uhsure.com>"]
|
||||||
description = "A simple DER/ASN.1 encoding/decoding library."
|
description = "A simple DER/ASN.1 encoding/decoding library."
|
||||||
categories = ["encoding"]
|
categories = ["encoding"]
|
||||||
keywords = ["ASN1","encoding","DER"]
|
keywords = ["ASN1","encoding","DER"]
|
||||||
license-file = "LICENSE"
|
license-file = "LICENSE"
|
||||||
repository = "https://github.com/acw/simple_asn1"
|
repository = "https://github.com/acw/simple_asn1"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "^0.4.0"
|
chrono = "^0.4.0"
|
||||||
|
|||||||
72
src/lib.rs
72
src/lib.rs
@@ -26,19 +26,11 @@
|
|||||||
//!
|
//!
|
||||||
//! Please send any bug reports, patches, and curses to the GitHub repository
|
//! Please send any bug reports, patches, and curses to the GitHub repository
|
||||||
//! at <code>https://github.com/acw/simple_asn1</code>.
|
//! at <code>https://github.com/acw/simple_asn1</code>.
|
||||||
extern crate chrono;
|
|
||||||
extern crate num_bigint;
|
|
||||||
extern crate num_traits;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate quickcheck;
|
|
||||||
#[cfg(test)]
|
|
||||||
extern crate rand;
|
|
||||||
|
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
pub use num_bigint::{BigInt, BigUint};
|
pub use num_bigint::{BigInt, BigUint};
|
||||||
use num_traits::{FromPrimitive, One, ToPrimitive, Zero};
|
use num_traits::{FromPrimitive, One, ToPrimitive, Zero};
|
||||||
use std::error::Error;
|
#[cfg(test)]
|
||||||
|
use quickcheck::quickcheck;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
@@ -324,9 +316,6 @@ pub enum ASN1DecodeErr {
|
|||||||
///
|
///
|
||||||
/// Invalid ASN.1 input can lead to this error.
|
/// Invalid ASN.1 input can lead to this error.
|
||||||
Incomplete,
|
Incomplete,
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
__Nonexhaustive,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ASN1DecodeErr {
|
impl fmt::Display for ASN1DecodeErr {
|
||||||
@@ -350,47 +339,10 @@ impl fmt::Display for ASN1DecodeErr {
|
|||||||
write!(f, "Invalid class value: {}", i),
|
write!(f, "Invalid class value: {}", i),
|
||||||
ASN1DecodeErr::Incomplete =>
|
ASN1DecodeErr::Incomplete =>
|
||||||
write!(f, "Incomplete data or invalid ASN1"),
|
write!(f, "Incomplete data or invalid ASN1"),
|
||||||
ASN1DecodeErr::__Nonexhaustive =>
|
|
||||||
panic!("A non exhaustive error should not be constructed"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for ASN1DecodeErr {
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
match self {
|
|
||||||
ASN1DecodeErr::EmptyBuffer =>
|
|
||||||
"Encountered an empty buffer decoding ASN1 block.",
|
|
||||||
ASN1DecodeErr::BadBooleanLength(_) =>
|
|
||||||
"Bad length field in boolean block.",
|
|
||||||
ASN1DecodeErr::LengthTooLarge(_) =>
|
|
||||||
"Length field too large for object type.",
|
|
||||||
ASN1DecodeErr::UTF8DecodeFailure(_) =>
|
|
||||||
"UTF8 string failed to properly decode.",
|
|
||||||
ASN1DecodeErr::PrintableStringDecodeFailure =>
|
|
||||||
"Printable string failed to properly decode.",
|
|
||||||
ASN1DecodeErr::InvalidDateValue(_) =>
|
|
||||||
"Invalid date value.",
|
|
||||||
ASN1DecodeErr::InvalidClass(_) =>
|
|
||||||
"Invalid class value",
|
|
||||||
ASN1DecodeErr::InvalidBitStringLength(_) =>
|
|
||||||
"Invalid length of bit string",
|
|
||||||
ASN1DecodeErr::Incomplete =>
|
|
||||||
"Incomplete data or invalid ASN1",
|
|
||||||
ASN1DecodeErr::__Nonexhaustive =>
|
|
||||||
panic!("A non exhaustive error should not be constructed"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cause(&self) -> Option<&dyn Error> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An error that can arise encoding ASN.1 primitive blocks.
|
/// An error that can arise encoding ASN.1 primitive blocks.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ASN1EncodeErr {
|
pub enum ASN1EncodeErr {
|
||||||
@@ -401,29 +353,15 @@ pub enum ASN1EncodeErr {
|
|||||||
|
|
||||||
impl fmt::Display for ASN1EncodeErr {
|
impl fmt::Display for ASN1EncodeErr {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.write_str(self.description())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for ASN1EncodeErr {
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
match self {
|
match self {
|
||||||
ASN1EncodeErr::ObjectIdentHasTooFewFields =>
|
ASN1EncodeErr::ObjectIdentHasTooFewFields =>
|
||||||
"ASN1 object identifier has too few fields.",
|
write!(f,"ASN1 object identifier has too few fields."),
|
||||||
ASN1EncodeErr::ObjectIdentVal1TooLarge =>
|
ASN1EncodeErr::ObjectIdentVal1TooLarge =>
|
||||||
"First value in ASN1 OID is too big.",
|
write!(f,"First value in ASN1 OID is too big."),
|
||||||
ASN1EncodeErr::ObjectIdentVal2TooLarge =>
|
ASN1EncodeErr::ObjectIdentVal2TooLarge =>
|
||||||
"Second value in ASN1 OID is too big."
|
write!(f,"Second value in ASN1 OID is too big."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cause(&self) -> Option<&dyn Error> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translate a binary blob into a series of `ASN1Block`s, or provide an
|
/// Translate a binary blob into a series of `ASN1Block`s, or provide an
|
||||||
|
|||||||
Reference in New Issue
Block a user