Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove rustc-serialize #5

Merged
merged 4 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ num-bigint = { version = "0.2", default-features = false }
num-integer = { version = "0.1", default-features = false }
bit-vec = "0.6"
lazy_static = "1"
rustc-serialize = "0.3"
chrono = "0.4"
b64-ct = "0.1.1"

[dev-dependencies]
rand = "0.3"
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

pub extern crate yasna;
pub extern crate num_bigint;
extern crate rustc_serialize;
extern crate b64_ct;
extern crate num_integer;
pub extern crate bit_vec;
#[macro_use]
Expand Down
8 changes: 4 additions & 4 deletions src/pem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use rustc_serialize::base64::{self, FromBase64, ToBase64};
use b64_ct::{FromBase64, ToBase64};

/// Type of the various `PEM_*` constants supplied to `pem_to_der` / `der_to_pem`.
pub struct PemGuard {
Expand Down Expand Up @@ -32,9 +32,9 @@ pub const PEM_CMS: &'static PemGuard = pem_guard!("CMS");
const BASE64_PEM_WRAP: usize = 64;

lazy_static!{
static ref BASE64_PEM: base64::Config = base64::Config {
char_set: base64::CharacterSet::Standard,
newline: base64::Newline::LF,
static ref BASE64_PEM: b64_ct::Config = b64_ct::Config {
char_set: b64_ct::CharacterSet::Standard,
newline: b64_ct::Newline::LF,
pad: true,
line_length: Some(BASE64_PEM_WRAP),
};
Expand Down
51 changes: 25 additions & 26 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub use yasna::models::{ObjectIdentifier, ParseOidError, TaggedDerValue};
use std::borrow::Cow;
use std::str;
use std::fmt;
use rustc_serialize::hex::ToHex;
use chrono::{self, Utc, Datelike, Timelike, TimeZone};

use {DerWrite, oid};
Expand Down Expand Up @@ -75,35 +74,35 @@ impl Name {
}
}

fn format_oid(oid: &ObjectIdentifier) -> String {
match oid::OID_TO_NAME.get(oid) {
Some(o) => o.to_string(),
None => oid.components().iter().map(|c| c.to_string()).collect::<Vec<_>>().join(".")
}
}
impl fmt::Display for Name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (i,v) in self.value.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}

fn format_der(der: &TaggedDerValue) -> String {
if der.pcbit() == PCBit::Constructed {
der.value().to_hex()
} else {
match der.tag() {
TAG_NUMERICSTRING | TAG_PRINTABLESTRING | TAG_IA5STRING | TAG_UTF8STRING => {
String::from_utf8_lossy(&der.value()).to_string()
// print key (oid)
if let Some(o) = oid::OID_TO_NAME.get(&v.0) {
write!(f, "{}", o)?;
} else {
for (j,c) in v.0.components().iter().enumerate() {
if j > 0 {
write!(f, ".")?;
}
write!(f, "{}", c)?;
}
}
_ => {
der.value().to_hex()
write!(f, "=")?;

// print value
match (v.1.pcbit(), v.1.tag()) {
(PCBit::Primitive, TAG_NUMERICSTRING) | (PCBit::Primitive, TAG_PRINTABLESTRING) | (PCBit::Primitive, TAG_IA5STRING) | (PCBit::Primitive, TAG_UTF8STRING) =>
write!(f, "{}", String::from_utf8_lossy(&v.1.value()))?,
_ => for &byte in v.1.value() {
write!(f, "{:x}", byte)?;
},
}
}
}
}

fn format_rdr(rdr: &(ObjectIdentifier, TaggedDerValue)) -> String {
format!("{}={}", format_oid(&rdr.0), format_der(&rdr.1))
}

impl fmt::Display for Name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value.iter().map(|rdr| format_rdr(rdr)).collect::<Vec<_>>().join(", "))?;
Ok(())
}
}
Expand Down