Skip to content

Commit

Permalink
TokenChallenge type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelrobert committed Jun 19, 2024
1 parent 13a3db6 commit 672c1c6
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 101 deletions.
31 changes: 31 additions & 0 deletions src/auth/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ impl TokenChallenge {
}
}

/// Returns the token type.
#[must_use]
pub const fn token_type(&self) -> TokenType {
self.token_type
}

/// Returns the issuer name.
#[must_use]
pub fn issuer_name(&self) -> String {
String::from_utf8_lossy(self.issuer_name.as_slice()).to_string()
}

/// Returns the redemption context.
#[must_use]
pub fn redemption_context(&self) -> Option<RedemptionContext> {
if self.redemption_context.is_empty() {
None
} else {
Some(self.redemption_context.as_slice().try_into().unwrap())
}
}

/// Returns the origin info.
#[must_use]
pub fn origin_info(&self) -> Vec<String> {
String::from_utf8_lossy(self.origin_info.as_slice())
.split(',')
.map(|s| s.to_string())
.collect()
}

/// Serializes the `TokenChallenge`.
///
/// # Errors
Expand Down
8 changes: 7 additions & 1 deletion tests/kat_batched_ristretto255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ async fn evaluate_kat(list: Vec<BatchedTokenTestVector>) {
.map(|blind| Ristretto255::deserialize_scalar(&blind.0).unwrap())
.collect();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::BatchedTokenRistretto255
);

// Client: Prepare a TokenRequest after having received a challenge
let (token_request, token_states) = client
.issue_token_request_with_params(&token_challenge, nonces, blinds)
Expand Down Expand Up @@ -183,7 +189,7 @@ async fn write_kat_batched_token_ristretto255() {
};

let kat_token_challenge = TokenChallenge::new(
privacypass::TokenType::BatchedTokenP384,
privacypass::TokenType::BatchedTokenRistretto255,
"Issuer Name",
redemption_context,
&["a".to_string(), "b".to_string(), "c".to_string()],
Expand Down
6 changes: 6 additions & 0 deletions tests/kat_batched_rp384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ async fn evaluate_kat(list: Vec<BatchedTokenTestVector>) {
.map(|blind| NistP384::deserialize_scalar(&blind.0).unwrap())
.collect();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::BatchedTokenP384
);

// Client: Prepare a TokenRequest after having received a challenge
let (token_request, token_states) = client
.issue_token_request_with_params(&token_challenge, nonces, blinds)
Expand Down
6 changes: 6 additions & 0 deletions tests/kat_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ async fn evaluate_kat(list: Vec<PrivateTokenTestVector>) {
.issue_token_request_with_params(&token_challenge, nonce, blind)
.unwrap();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::PrivateToken
);

// KAT: Check token request
assert_eq!(
token_request.tls_serialize_detached().unwrap(),
Expand Down
6 changes: 6 additions & 0 deletions tests/kat_public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ async fn evaluate_kat(list: Vec<PublicTokenTestVector>) {
TokenChallenge::deserialize(vector.token_challenge.as_slice()).unwrap();
let challenge_digest: [u8; 32] = token_challenge.digest().unwrap();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::PublicToken
);

let (token_request, token_state) = client
.issue_token_request(det_rng, token_challenge)
.unwrap();
Expand Down
Loading

0 comments on commit 672c1c6

Please sign in to comment.