#![cfg(test)]
use super::*;
use crate::delegation::artifact::{DelegationRole, DelegationSubjectKind};
#[path = "encoding_tests/decode_envelope.rs"]
mod decode_envelope;
#[path = "encoding_tests/decode_payload.rs"]
mod decode_payload;
#[path = "encoding_tests/encodable.rs"]
mod encodable;
#[path = "encoding_tests/layout.rs"]
mod layout;
const ROOT_KEY: [u8; KEY_LEN] = [0xa1; KEY_LEN];
const SIGNATURE: [u8; 64] = [0x5e; 64];
const SEQUENCE_ENTRY_LEN: usize = 4;
const SEQUENCE: u64 = 300;
fn delegated_key() -> [u8; KEY_LEN] {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("delegated.key");
std::fs::write(&path, [0x42u8; 32]).unwrap();
crate::Ed25519Identity::load(&path)
.unwrap()
.public_key_bytes()
}
fn claim() -> DelegationClaim {
DelegationClaim {
subject_kind: DelegationSubjectKind::Domain,
subject_value: "example.test".to_string(),
delegated_public_key: delegated_key(),
role: DelegationRole::Operational,
not_before_unix_ms: 1_700_000_000_000,
sequence: SEQUENCE,
}
}
fn seat_claim() -> DelegationClaim {
DelegationClaim {
subject_kind: DelegationSubjectKind::Seat,
subject_value: SEAT.to_string(),
delegated_public_key: delegated_key(),
role: DelegationRole::SpeaksFor,
not_before_unix_ms: 1_700_000_000_000,
sequence: SEQUENCE,
}
}
const SEAT: &str = "example.test";
fn expected_protected(key: &[u8; KEY_LEN]) -> Vec<u8> {
let mut out = vec![
0xa3, 0x01, 0x27, 0x03, 0x78, 0x26, ];
out.extend_from_slice(b"application/vnd.lys.delegation.v1+cbor");
out.extend_from_slice(&[0x04, 0x58, 0x20]); out.extend_from_slice(key);
out
}
fn expected_payload(delegated: &[u8; KEY_LEN]) -> Vec<u8> {
let mut out = vec![
0xa6, 0x01, 0x01, 0x02, 0x6c, ];
out.extend_from_slice(b"example.test");
out.extend_from_slice(&[0x03, 0x58, 0x20]); out.extend_from_slice(delegated);
out.extend_from_slice(&[0x04, 0x02]);
out.extend_from_slice(&[0x05, 0x1b]);
out.extend_from_slice(&1_700_000_000_000u64.to_be_bytes());
out.extend_from_slice(&[0x06, 0x19, 0x01, 0x2c]);
out
}
fn unusable_keys() -> [[u8; KEY_LEN]; 3] {
let mut identity_point = [0u8; KEY_LEN];
identity_point[0] = 1;
[[0u8; KEY_LEN], [0xffu8; KEY_LEN], identity_point]
}
fn role_offset(payload: &[u8]) -> usize {
let not_before_entry_len = 10;
let at = payload.len() - SEQUENCE_ENTRY_LEN - not_before_entry_len - 2;
assert_eq!(payload[at], 0x04, "label 4 must be where the tail puts it");
assert_eq!(
payload[at + 2],
0x05,
"label 5 must immediately follow the role value"
);
at
}