1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! Signature-role profile facts, separate from strict acceptance.
use ;
use crate::;
use Work;
/// A scoped recognized scheme and its readable parameter-profile diagnostics.
///
/// This is not a validated [`super::Algorithm`] or permission to call a provider.
/// Fixed-scheme recognition survives unwanted parameters; their original bytes
/// remain available through [`Self::identifier`]. No parameter is rewritten.
/// Inspects signature-role parameters without weakening [`super::with_algorithm`].
///
/// Uses exactly the strict resolver's recognized OIDs and parameter rules.
/// Readable NULL/absence violations retain their scheme and original fault;
/// this API does not decide whether mathematical verification is appropriate.
/// Fixed cases allocate nothing. PSS uses [`pss::inspect`]'s schema kernel and
/// accounted diagnostics, including readable DER written DEFAULTs. Missing PSS
/// signature parameters retain `Some(Scheme::RsaPss)` plus `MissingField`, with
/// no fabricated parameters (RFC4055 ยง3.1). Optional PSS key restrictions still
/// use `pss::inspect`, where absence is unrestricted, not a signature fault.
/// <https://www.rfc-editor.org/rfc/rfc4055#section-3.1>
///
/// Original/current ceilings apply before classification or parameter traversal.
/// The callback borrows temporary parameters and diagnostics only for the visit;
/// its result is returned unchanged, including caller-specific errors. Original
/// document views may escape, but temporary descriptor references may not.
///
/// # Errors
/// Malformed or ambiguous PSS grammar and terminal resource/processing refusal
/// prevent the visit. Structural ASN.1 inspection is a separate operation:
/// [`super::super::read_inspection`] does not fabricate a valid identifier from
/// malformed parameter encoding for this function.
///
/// # Examples
/// ```
/// use std::sync::Arc;
/// use structured_asn1::{Parser, memory::{Memory, MemoryAccount}};
/// use structured_pkix::algorithm::{self, digest, signature};
/// let work = Memory::new(Arc::new(MemoryAccount::new(4096, 4096)));
/// let source = Parser::der(work.clone());
/// // ecdsa-with-SHA256 with a readable but forbidden NULL parameter.
/// let bytes = b"\x30\x0c\x06\x08\x2a\x86\x48\xce\x3d\x04\x03\x02\x05\x00";
/// let mut reader = source.read(bytes, 400).unwrap();
/// let element = reader.next_element().unwrap().unwrap();
/// let identifier = algorithm::read(&reader, &element, "signatureAlgorithm")?;
/// signature::with_inspection(identifier, &work, |reading| {
/// assert_eq!(reading.scheme(), Some(signature::Scheme::Ecdsa(digest::Algorithm::Sha256)));
/// assert_eq!(reading.faults()[0].offset(), 412);
/// })?;
/// assert!(signature::with_algorithm(identifier, &work, |_| ()).is_err());
/// # Ok::<(), structured_pkix::Error>(())
/// ```
/// A reference to a temporary diagnostic or PSS descriptor cannot escape:
/// ```compile_fail
/// use structured_pkix::{Error, algorithm::{AlgorithmIdentifier, signature}};
/// use structured_asn1::memory::Memory;
/// fn escape<'a>(id: AlgorithmIdentifier<'a>, work: &Memory) -> &'a [Error] {
/// signature::with_inspection(id, work, |reading| reading.faults()).unwrap()
/// }
/// ```