项目作者: Rahix

项目描述 :
A Rust asn1 library
高级语言: Rust
项目地址: git://github.com/Rahix/eagre-asn1.git
创建时间: 2016-06-16T15:25:46Z
项目社区:https://github.com/Rahix/eagre-asn1

开源协议:Other

下载


Build Status

eagre-asn1

eagre-asn1 is an asn1 library for Rust.

It makes heavy use of macros to make the interface easy to use.

Currently only DER and a very small bit of xer is supported.

Documentation

Documentation can be found at https://rahix.github.io/eagre-asn1/

Example

Say you have the following asn1 structure:

  1. User ::= SEQUENCE {
  2. username UTF8String,
  3. passwordHash [CONTEXT 12] IMPLICIT OctetString,
  4. age [APPLICATION 1] EXPLICIT Integer,
  5. admin Boolean
  6. }

In Rust it would look like this:

  1. struct User {
  2. pub username: String,
  3. pub password_hash: Vec<u8>,
  4. pub age: i32,
  5. pub admin: bool,
  6. }
  7. der_sequence!{
  8. User:
  9. username: NOTAG TYPE String,
  10. password_hash: IMPLICIT TAG CONTEXT 12; TYPE Vec<u8>,
  11. age: EXPLICIT TAG APPLICATION 1; TYPE i32,
  12. admin: NOTAG TYPE bool,
  13. }

And serializing is as easy as:

  1. use eagre_asn1::der::DER;
  2. let some_user = User { ... };
  3. let encoded = some_user.der_bytes().unwrap();
  4. // Send to far away planet
  5. let decoded = User::der_from_bytes(encoded).unwrap();
  6. assert_eq!(some_user, decoded);

Implemented Types

  • Any types::Any
  • BitString types::BitString
  • BMPString types::BMPString
  • Boolean bool
  • CharacterString types::CharacterString
  • Choice enum
  • Date types::Date
  • DateTime types::DateTime
  • Duration std::time::Duration
  • EmbeddedPDV types::EmbeddedPDV
  • Enumeration enum
  • External
  • GeneralString types::GeneralString
  • GraphicString types::GraphicString
  • IA5String types::IA5String
  • InstanceOf
  • Integer i32
  • IRI
  • Null types::Null
  • NumericString types::NumericString
  • ObjectClassField
  • ObjectIdentifier
  • OctetString Vec<u8>
  • PrintableString types::PrintableString
  • Real f32
  • RelativeIRI
  • RelativeOID
  • Sequence struct
  • Sequence Of Vec<T>
  • Set struct
  • Set Of types::SetOf
  • T61String types::T61String
  • Time types::Time
  • TimeOfDay types::TimeOfDay
  • UniversalString types::UniversalString
  • UTF8String String or &str
  • VideotexString types::VideotexString
  • VisibleString types::VisibleString

License

eagre-asn1 is licensed under either of

at your option.