Skip to content

Commit

Permalink
typos + move api_test.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulmth committed Dec 6, 2023
1 parent 4b707c2 commit d8db8d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ impl<H: Hasher> SdObjectEncoder<H> {
}

fn gen_rand(len: usize) -> String {
let mut bytes = vec![0; len];
let mut rng = rand::thread_rng();
let random_bytes: Vec<u8> = (0..len).map(|_| rng.gen()).collect();
multibase::Base::Base64Url.encode(random_bytes)
rng.fill(&mut bytes[..]);

multibase::Base::Base64Url.encode(bytes)
}

/// Returns a reference to the internal object.
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ pub enum Error {
#[error("{0}")]
Unspecified(String),

#[error("salt size must be greater or equal 16")]
#[error("salt size must be greater than or equal to 16")]
InvalidSaltSize,
}
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#[cfg(test)]
mod api_test;
mod decoder;
mod disclosure;
mod encoder;
Expand Down
14 changes: 7 additions & 7 deletions src/api_test.rs → tests/api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use serde_json::json;
use serde_json::Map;
use serde_json::Value;

use crate::Disclosure;
use crate::SdJwt;
use crate::SdObjectDecoder;
use crate::SdObjectEncoder;
use sd_jwt::Disclosure;
use sd_jwt::SdJwt;
use sd_jwt::SdObjectDecoder;
use sd_jwt::SdObjectEncoder;

#[test]
fn test_complex_structure() {
Expand Down Expand Up @@ -169,7 +169,7 @@ fn decode() {
// Values taken from https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-06.html#name-example-2-handling-structur
let sd_jwt = "eyJhbGciOiAiRV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1ZWptc0JNb0d3dU5YaDlxQUFGQVRBY2k0MG9pZEVlVnNBIiwgInVOSG9XWWhYc1poVkpDTkUyRHF5LXpxdDd0NjlnSkt5NVFhRnY3R3JNWDQiXX0sICJfc2RfYWxnIjogInNoYS0yNTYifQ.IjE4EfnYu1RZ1uz6yqtFh5Lppq36VC4VeSr-hLDFpZ9zqBNmMrT5JHLLXTuMJqKQp3NIzDsLaft4GK5bYyfqhg~WyJHMDJOU3JRZmpGWFE3SW8wOXN5YWpBIiwgInJlZ2lvbiIsICJcdTZlMmZcdTUzM2EiXQ~WyJsa2x4RjVqTVlsR1RQVW92TU5JdkNBIiwgImNvdW50cnkiLCAiSlAiXQ~";
let sd_jwt: SdJwt = SdJwt::parse(sd_jwt).unwrap();
let (payload, _header) = jwt::decode_with_verifier(&sd_jwt.jwt, &DeocyJwsVerifier {}).unwrap();
let (payload, _header) = jwt::decode_with_verifier(&sd_jwt.jwt, &DecoyJwsVerifier {}).unwrap();
let decoder = SdObjectDecoder::new_with_sha256();
let decoded: Map<String, Value> = decoder.decode(payload.claims_set(), &sd_jwt.disclosures).unwrap();
let expected_object = json!({
Expand Down Expand Up @@ -202,8 +202,8 @@ impl JwsAlgorithm for DecoyJwsAlgorithm {
}

#[derive(Debug, Clone)]
struct DeocyJwsVerifier;
impl JwsVerifier for DeocyJwsVerifier {
struct DecoyJwsVerifier;
impl JwsVerifier for DecoyJwsVerifier {
fn algorithm(&self) -> &dyn josekit::jws::JwsAlgorithm {
&DecoyJwsAlgorithm {}
}
Expand Down

0 comments on commit d8db8d4

Please sign in to comment.