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
54 changes: 27 additions & 27 deletions cmpv2/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,33 @@ flags! {
/// [RFC 4210 Section 5.2.3]: https://www.rfc-editor.org/rfc/rfc4210#section-5.2.3
#[allow(missing_docs)]
pub enum PkiFailureInfoValues: u32 {
BadAlg = 0,
BadMessageCheck = 1,
BadRequest = 2,
BadTime = 3,
BadCertId = 4,
BadDataFormat = 5,
WrongAuthority = 6,
IncorrectData = 7,
MissingTimeStamp = 8,
BadPOP = 9,
CertRevoked = 10,
CertConfirmed = 11,
WrongIntegrity = 12,
BadRecipientNonce = 13,
TimeNotAvailable = 14,
UnacceptedPolicy = 15,
UnacceptedExtension = 16,
AddInfoNotAvailable = 17,
BadSenderNonce = 18,
BadCertTemplate = 19,
SignerNotTrusted = 20,
TransactionIdInUse = 21,
UnsupportedVersion = 22,
NotAuthorized = 23,
SystemUnavail = 24,
SystemFailure = 25,
DuplicateCertReq = 26,
BadAlg = 1 << 0,
BadMessageCheck = 1 << 1,
BadRequest = 1 << 2,
BadTime = 1 << 3,
BadCertId = 1 << 4,
BadDataFormat = 1 << 5,
WrongAuthority = 1 << 6,
IncorrectData = 1 << 7,
MissingTimeStamp = 1 << 8,
BadPOP = 1 << 9,
CertRevoked = 1 << 10,
CertConfirmed = 1 << 11,
WrongIntegrity = 1 << 12,
BadRecipientNonce = 1 << 13,
TimeNotAvailable = 1 << 14,
UnacceptedPolicy = 1 << 15,
UnacceptedExtension = 1 << 16,
AddInfoNotAvailable = 1 << 17,
BadSenderNonce = 1 << 18,
BadCertTemplate = 1 << 19,
SignerNotTrusted = 1 << 20,
TransactionIdInUse = 1 << 21,
UnsupportedVersion = 1 << 22,
NotAuthorized = 1 << 23,
SystemUnavail = 1 << 24,
SystemFailure = 1 << 25,
DuplicateCertReq = 1 << 26,
}
}

Expand Down
44 changes: 44 additions & 0 deletions cmpv2/tests/failure_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! `PKIFailureInfo` tests.

use cmpv2::body::PkiBody;
use cmpv2::message::PkiMessage;
use cmpv2::status::{PkiFailureInfo, PkiFailureInfoValues};
use der::{Decode, Encode};
use hex_literal::hex;

/// `PKIFailureInfo ::= BIT STRING { badAlg (0), badMessageCheck (1), badRequest (2), ... }`:
/// each named value is the bit at that position.
#[test]
fn failure_info_bit_positions() {
let cases: [(PkiFailureInfoValues, &[u8]); 6] = [
(PkiFailureInfoValues::BadAlg, &hex!("03020780")),
(PkiFailureInfoValues::BadMessageCheck, &hex!("03020640")),
(PkiFailureInfoValues::BadRequest, &hex!("03020520")),
(PkiFailureInfoValues::WrongAuthority, &hex!("03020102")),
(PkiFailureInfoValues::BadPOP, &hex!("0303060040")),
(
PkiFailureInfoValues::DuplicateCertReq,
&hex!("03050500000020"),
),
];
for (value, der) in cases {
let info = PkiFailureInfo::from(value);
assert_eq!(info.to_der().unwrap(), der, "{value:?}");
assert_eq!(PkiFailureInfo::from_der(der).unwrap(), info, "{value:?}");
}
}

/// The failInfo in `failed_kur_rsp_01.bin` (an OpenSSL error response, statusString
/// "wrong certid") is `03 02 05 20`: bit 2, badRequest.
#[test]
fn failure_info_from_openssl_response() {
let message = PkiMessage::from_der(include_bytes!("examples/failed_kur_rsp_01.bin")).unwrap();
let PkiBody::Error(err) = &message.body else {
panic!("expected error");
};
let fail_info = err.pki_status_info.fail_info.unwrap();
assert_eq!(
fail_info,
PkiFailureInfo::from(PkiFailureInfoValues::BadRequest)
);
}
Loading