Skip to content

Commit 35558f6

Browse files
bors[bot]AdrianCX
andauthored
Merge #5
5: remove rustc-serialize r=jethrogb a=AdrianCX Moved from rustc-serialize to b64-ct and custom to-hex Might need to update the version in Cargo.toml after crates.io update Co-authored-by: Adrian Cruceru <[email protected]>
2 parents affd81b + f0e7a81 commit 35558f6

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ num-bigint = { version = "0.2", default-features = false }
1212
num-integer = { version = "0.1", default-features = false }
1313
bit-vec = "0.6"
1414
lazy_static = "1"
15-
rustc-serialize = "0.3"
1615
chrono = "0.4"
16+
b64-ct = "0.1.1"
1717

1818
[dev-dependencies]
1919
rand = "0.3"

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
pub extern crate yasna;
1111
pub extern crate num_bigint;
12-
extern crate rustc_serialize;
12+
extern crate b64_ct;
1313
extern crate num_integer;
1414
pub extern crate bit_vec;
1515
#[macro_use]

src/pem.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

7-
use rustc_serialize::base64::{self, FromBase64, ToBase64};
7+
use b64_ct::{FromBase64, ToBase64};
88

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

3434
lazy_static!{
35-
static ref BASE64_PEM: base64::Config = base64::Config {
36-
char_set: base64::CharacterSet::Standard,
37-
newline: base64::Newline::LF,
35+
static ref BASE64_PEM: b64_ct::Config = b64_ct::Config {
36+
char_set: b64_ct::CharacterSet::Standard,
37+
newline: b64_ct::Newline::LF,
3838
pad: true,
3939
line_length: Some(BASE64_PEM_WRAP),
4040
};

src/types.rs

+25-26
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub use yasna::models::{ObjectIdentifier, ParseOidError, TaggedDerValue};
1010
use std::borrow::Cow;
1111
use std::str;
1212
use std::fmt;
13-
use rustc_serialize::hex::ToHex;
1413
use chrono::{self, Utc, Datelike, Timelike, TimeZone};
1514

1615
use {DerWrite, oid};
@@ -75,35 +74,35 @@ impl Name {
7574
}
7675
}
7776

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

85-
fn format_der(der: &TaggedDerValue) -> String {
86-
if der.pcbit() == PCBit::Constructed {
87-
der.value().to_hex()
88-
} else {
89-
match der.tag() {
90-
TAG_NUMERICSTRING | TAG_PRINTABLESTRING | TAG_IA5STRING | TAG_UTF8STRING => {
91-
String::from_utf8_lossy(&der.value()).to_string()
84+
// print key (oid)
85+
if let Some(o) = oid::OID_TO_NAME.get(&v.0) {
86+
write!(f, "{}", o)?;
87+
} else {
88+
for (j,c) in v.0.components().iter().enumerate() {
89+
if j > 0 {
90+
write!(f, ".")?;
91+
}
92+
write!(f, "{}", c)?;
93+
}
9294
}
93-
_ => {
94-
der.value().to_hex()
95+
write!(f, "=")?;
96+
97+
// print value
98+
match (v.1.pcbit(), v.1.tag()) {
99+
(PCBit::Primitive, TAG_NUMERICSTRING) | (PCBit::Primitive, TAG_PRINTABLESTRING) | (PCBit::Primitive, TAG_IA5STRING) | (PCBit::Primitive, TAG_UTF8STRING) =>
100+
write!(f, "{}", String::from_utf8_lossy(&v.1.value()))?,
101+
_ => for &byte in v.1.value() {
102+
write!(f, "{:x}", byte)?;
103+
},
95104
}
96105
}
97-
}
98-
}
99-
100-
fn format_rdr(rdr: &(ObjectIdentifier, TaggedDerValue)) -> String {
101-
format!("{}={}", format_oid(&rdr.0), format_der(&rdr.1))
102-
}
103-
104-
impl fmt::Display for Name {
105-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
106-
write!(f, "{}", self.value.iter().map(|rdr| format_rdr(rdr)).collect::<Vec<_>>().join(", "))?;
107106
Ok(())
108107
}
109108
}

0 commit comments

Comments
 (0)