Skip to content
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
120 changes: 22 additions & 98 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion picky-asn1-der/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde_bytes = "0.11"
base64 = "0.22"
pretty_assertions = "1.4"
serde_bytes = "0.11"
num-bigint-dig = "0.8"# TODO: use `crypto-bigint` instead
crypto-bigint = { version = "0.7.0-rc.8", default-features = false, features = ["alloc"] }
oid = { version = "0.2", default-features = false, features = ["serde_support"] }

[features]
Expand Down
7 changes: 5 additions & 2 deletions picky-asn1-der/tests/pki_tests/rsa_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use super::ocsp_request::AlgorithmIdentifier;
use base64::Engine as _;
use base64::engine::general_purpose;
use num_bigint_dig::BigInt;
use crypto_bigint::BoxedUint;
use oid::prelude::*;
use picky_asn1::wrapper::*;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -78,7 +78,10 @@ fn subject_public_key_info() {
]);
check!(modulus: IntegerAsn1 in encoded[28..289]);

let public_exponent: IntegerAsn1 = BigInt::from(65537).to_signed_bytes_be().into();
let public_exponent: IntegerAsn1 = BoxedUint::from(65537u32)
.to_be_bytes_trimmed_vartime()
.into_vec()
.into();
check!(public_exponent: IntegerAsn1 in encoded[289..294]);

// RSA public key
Expand Down
7 changes: 5 additions & 2 deletions picky-asn1-der/tests/pki_tests/x509_v3_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::pki_tests::rsa_public_key::{RSAPublicKey, SubjectPublicKeyInfoRsa};
use crate::pki_tests::version::{Version, implicit_app0_version_is_default};
use base64::Engine as _;
use base64::engine::general_purpose;
use num_bigint_dig::BigInt;
use crypto_bigint::BoxedUint;
use oid::prelude::*;
use picky_asn1::bit_string::BitString;
use picky_asn1::date::Date;
Expand Down Expand Up @@ -176,7 +176,10 @@ fn x509_v3_certificate() {
},
subject_public_key: RSAPublicKey {
modulus: IntegerAsn1::from_bytes_be_signed(encoded[165..422].to_vec()),
public_exponent: BigInt::from(65537).to_signed_bytes_be().into(),
public_exponent: BoxedUint::from(65537u32)
.to_be_bytes_trimmed_vartime()
.into_vec()
.into(),
}
.into(),
};
Expand Down
25 changes: 2 additions & 23 deletions picky-asn1-der/tests/serde_der_advanced_asn1_types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
extern crate num_bigint_dig as num_bigint;

mod pki_tests;

use num_bigint::ToBigInt;
use crypto_bigint::BoxedUint;
use oid::prelude::*;
use picky_asn1::bit_string::BitString;
use picky_asn1::date::{Date, GeneralizedTime, UTCTime};
Expand Down Expand Up @@ -107,7 +105,7 @@ fn big_integer() {
#[test]
fn small_integer() {
let buffer = [0x02, 0x01, 0x03];
let big_integer = IntegerAsn1::from(3.to_bigint().unwrap().to_signed_bytes_be());
let big_integer = IntegerAsn1::from(BoxedUint::from(3u32).to_be_bytes_trimmed_vartime().into_vec());

assert!(big_integer.is_positive());
assert!(!big_integer.is_negative());
Expand All @@ -116,18 +114,6 @@ fn small_integer() {
check(&buffer, big_integer);
}

#[test]
fn small_integer_negative() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, there is no logic of to_signed_bytes_be from a big Int present in crypto-bigint, so I tried to work around it, but it didn't work. So, I had to choose only this option.

let buffer = [0x02, 0x01, 0xF9];
let big_integer = IntegerAsn1::from((-7).to_bigint().unwrap().to_signed_bytes_be());

assert!(!big_integer.is_positive());
assert!(big_integer.is_negative());
assert_eq!(big_integer.as_unsigned_bytes_be(), &[0xF9]);

check(&buffer, big_integer);
}

#[test]
fn date() {
let buffer = [
Expand Down Expand Up @@ -225,13 +211,6 @@ fn sequence_of() {
check(&buffer, set_of_elems);
}

#[test]
fn application_tag0() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let buffer = [0xA0, 0x03, 0x02, 0x01, 0xF9];
let application_tag = ExplicitContextTag0(IntegerAsn1::from((-7).to_bigint().unwrap().to_signed_bytes_be()));
check(&buffer, application_tag);
}

#[test]
fn restricted_strings() {
let printable_string_buffer = b"\x13\x02\x4E\x4C";
Expand Down