Skip to content

Commit

Permalink
Update ring version to 0.17.5
Browse files Browse the repository at this point in the history
  • Loading branch information
olger committed Oct 27, 2023
1 parent 16d5c91 commit e60e4d1
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 43 deletions.
137 changes: 106 additions & 31 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data-encoding = "2.3.2"
once_cell = "1.16.0"
num-bigint = "0.4"
num-traits = "0.2"
ring = "~0.16.20"
ring = "~0.17.5"
serde = { version = "1.0.147", features=["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }

Expand Down
2 changes: 1 addition & 1 deletion src/jwa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl SignatureAlgorithm {
};

let rng = rand::SystemRandom::new();
let mut signature = vec![0; key_pair.public_modulus_len()];
let mut signature = vec![0; key_pair.public().modulus_len()];
let padding_algorithm: &dyn signature::RsaEncoding = match algorithm {
SignatureAlgorithm::RS256 => &signature::RSA_PKCS1_SHA256,
SignatureAlgorithm::RS384 => &signature::RSA_PKCS1_SHA384,
Expand Down
6 changes: 5 additions & 1 deletion src/jws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ impl Secret {
SignatureAlgorithm::ES384 => &signature::ECDSA_P384_SHA384_FIXED_SIGNING,
_ => return Err(Error::UnsupportedOperation),
};
let key_pair = signature::EcdsaKeyPair::from_pkcs8(ring_algorithm, der.as_slice())?;
let key_pair = signature::EcdsaKeyPair::from_pkcs8(
ring_algorithm,
der.as_slice(),
&ring::rand::SystemRandom::new(),
)?;
Ok(Secret::EcdsaKeyPair(Arc::new(key_pair)))
}

Expand Down
3 changes: 2 additions & 1 deletion src/jws/flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ impl SignedData {
/// &ECDSA_P256_SHA256_FIXED_SIGNING,
/// &ring::rand::SystemRandom::new())?;
/// let keypair = EcdsaKeyPair::from_pkcs8(
/// &ECDSA_P256_SHA256_FIXED_SIGNING, pkcs8.as_ref())?;
/// &ECDSA_P256_SHA256_FIXED_SIGNING, pkcs8.as_ref(),
/// &ring::rand::SystemRandom::new())?;
/// let secret = Secret::EcdsaKeyPair(Arc::new(keypair));
/// let signed = SignedData::sign(data, secret)?;
/// # Ok::<(), biscuit::errors::Error>(())
Expand Down
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,11 @@ impl From<Timestamp> for DateTime<Utc> {

impl From<i64> for Timestamp {
fn from(timestamp: i64) -> Self {
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc).into()
DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(),
Utc,
)
.into()
}
}

Expand All @@ -719,7 +723,7 @@ impl<'de> Deserialize<'de> for Timestamp {
{
let timestamp = i64::deserialize(deserializer)?;
Ok(Timestamp(DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp(timestamp, 0),
NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(),
Utc,
)))
}
Expand Down Expand Up @@ -1337,7 +1341,7 @@ mod tests {
#[test]
fn validate_times_catch_future_token() {
let temporal_options = TemporalOptions {
now: Some(Utc.timestamp(0, 0)),
now: Some(Utc.timestamp_opt(0, 0).unwrap()),
..Default::default()
};

Expand All @@ -1358,7 +1362,7 @@ mod tests {
#[test]
fn validate_times_catch_too_old_token() {
let temporal_options = TemporalOptions {
now: Some(Utc.timestamp(40, 0)),
now: Some(Utc.timestamp_opt(40, 0).unwrap()),
..Default::default()
};

Expand All @@ -1379,7 +1383,7 @@ mod tests {
#[test]
fn validate_times_catch_expired_token() {
let temporal_options = TemporalOptions {
now: Some(Utc.timestamp(2, 0)),
now: Some(Utc.timestamp_opt(2, 0).unwrap()),
..Default::default()
};

Expand All @@ -1397,7 +1401,7 @@ mod tests {
#[test]
fn validate_times_catch_early_token() {
let temporal_options = TemporalOptions {
now: Some(Utc.timestamp(0, 0)),
now: Some(Utc.timestamp_opt(0, 0).unwrap()),
..Default::default()
};

Expand Down Expand Up @@ -1520,7 +1524,7 @@ mod tests {
};

let temporal_options = TemporalOptions {
now: Some(Utc.timestamp(100, 0)),
now: Some(Utc.timestamp_opt(100, 0).unwrap()),
..Default::default()
};

Expand Down Expand Up @@ -1548,7 +1552,7 @@ mod tests {
};

let temporal_options = TemporalOptions {
now: Some(Utc.timestamp(100, 0)),
now: Some(Utc.timestamp_opt(100, 0).unwrap()),
epsilon: Duration::seconds(10),
};

Expand Down

0 comments on commit e60e4d1

Please sign in to comment.