Skip to main content

profile_faults

Function profile_faults 

Source
pub fn profile_faults<'a>(
    signer: &SignerInfo<'a>,
    role: Role,
    parent: &Reader<'a>,
) -> Result<OwnedVec<Error>>
Expand description

Reports every CAdES profile violation of one SignerInfo, in rule order, with original locations.

The signer’s own ESS signing-certificate attributes are read here, so the policies field §§5.2.2.2-5.2.2.3 forbid is always judged on this signer, never on attributes read from another. An attribute this crate does not read is judged only by its placement, value count and, for the ESS content attributes, a repeated instance (RFC 2634 §1.3.4), plus the signaturePolicyImplied choice that §5.2.9.1 forbids. An empty result is not a level or validity verdict.

§Examples

use std::sync::Arc;
use structured_asn1::Parser;
use structured_asn1::memory::{Memory, MemoryAccount};
use structured_cms::cades::{Role, profile_faults};
use structured_cms::{ErrorCode, SignedData, oid};

fn tlv(tag: u8, contents: &[u8]) -> Vec<u8> {
    [&[tag, contents.len() as u8][..], contents].concat()
}
// One signer whose signed attributes hold a mime-type, which §5.2.4.2
// forbids only within a countersignature.
let mime = tlv(0x30, &[tlv(6, oid::MIME_TYPE.as_bytes()), tlv(0x31, &tlv(12, b"text/plain"))].concat());
let signer = [
    &[2, 1, 3, 0x80, 1, 7][..],
    &tlv(0x30, &tlv(6, oid::SHA256.as_bytes())),
    &tlv(0xa0, &mime),
    &tlv(0x30, &tlv(6, &[0x2b, 0x65, 0x70])),
    &tlv(4, &[8]),
]
.concat();
let inside = [
    &[2, 1, 3, 0x31, 0][..],
    &tlv(0x30, &tlv(6, oid::DATA.as_bytes())),
    &tlv(0x31, &tlv(0x30, &signer)),
]
.concat();
let message = tlv(0x30, &[tlv(6, oid::SIGNED_DATA.as_bytes()), tlv(0xa0, &tlv(0x30, &inside))].concat());

let parser = Parser::ber(Memory::new(Arc::new(MemoryAccount::new(65536, 65536))));
let value = SignedData::read(&parser, &message, 0).unwrap();
let query = parser.read(&[], 0).unwrap();
let info = &value.signers()[0];
assert!(profile_faults(info, Role::Signature, &query).unwrap().is_empty());
let faults = profile_faults(info, Role::Countersignature, &query).unwrap();
assert_eq!(faults[0].code(), ErrorCode::AttributePlacement);

§Errors

A foreign reader, signing-certificate attributes the ESS reader refuses (SigningAttributes::read), or a spent work or memory ceiling; never a violation.