silk.tls.trust_snapshot.
A fixed list of trust anchors: the root CAs that certificate path validation starts from.
When to use#
Make a TrustSnapshot from your CA certificates with TrustSnapshot.fromPem, or from
anchors with limits with TrustSnapshot.fromAnchors. Pass it to path validation or to a TLS
client. Use TrustSnapshot.combine to add your own CAs to another snapshot.
Details#
A snapshot keeps its anchors in input order, with duplicates, and does not change after you make
it. SnapshotLimits and TrustLoadLimits bound its size. An empty snapshot is valid: it
trusts no certificate.
Errors#
TrustSourceErrorif a certificate is not valid, or a limit is exceeded.OutOfMemoryErrorif theAllocatorfails.
Gotchas#
A snapshot is only a list of authorities. It does not check chains, names, dates, or revocation, and it is not the trust store of the operating system.
Examples#
Make an empty snapshot#
import silk.collections.list { List }
import silk.core.result { Result }
import silk.tls.trust_anchor { TrustAnchor }
import silk.tls.trust_snapshot { SnapshotLimits, TrustSnapshot, TrustSourceError }
pub fn main() -> i32 {
return match TrustSnapshot.fromAnchors(List<TrustAnchor>.make(), SnapshotLimits.defaults()) {
Result<TrustSnapshot, TrustSourceError>.Success { value } => {
// An empty snapshot is valid, but no certificate chains to it.
if TrustSnapshot.anchors(&value).length != 0 {
return 1
}
return 0
}
Result<TrustSnapshot, TrustSourceError>.Failure { error: _ } => 1
}
}Import as TrustSnapshot with import silk.tls.trust_snapshot { TrustSnapshot }.
Public declarations: 7.
SnapshotLimits#
pub struct SnapshotLimitsThe limits for one snapshot. Each limit is inclusive, and 0 allows nothing.
Field anchors#
pub anchors: usizeThe maximum number of anchors, with duplicates.
Field encodedBytes#
pub encodedBytes: usizeThe maximum size of all anchors, as TrustAnchor.encodedBytes counts it.
Implementation Copy for SnapshotLimits#
impl Copy for SnapshotLimitsImplementation SnapshotLimits#
impl SnapshotLimitsAssociated function defaults#
pub fn defaults() -> SnapshotLimitsReturns the default limits: 1024 anchors and 8 MiB.
TrustLoadLimits#
pub struct TrustLoadLimitsThe limits for loading trust: the certificate decoder limits and the snapshot limits.
Field decode#
pub decode: DecodeLimitsThe limits for decoding PEM and certificates.
Field snapshot#
pub snapshot: SnapshotLimitsThe limits for the snapshot.
Implementation Copy for TrustLoadLimits#
impl Copy for TrustLoadLimitsImplementation TrustLoadLimits#
impl TrustLoadLimitsAssociated function defaults#
pub fn defaults() -> TrustLoadLimitsReturns DecodeLimits.defaults() and SnapshotLimits.defaults.
TrustLimitKind#
pub enum TrustLimitKindThe limit that a trust load exceeded.
AnchorCount#
AnchorCountThe number of anchors.
EncodedBytes#
EncodedBytesThe size of all anchors.
InputBytes#
InputBytesThe size of a file that a native trust source reads.
Implementation Debug for TrustLimitKind#
impl Debug for TrustLimitKindOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the variant, such as AnchorCount.
TrustConfigurationReason#
pub enum TrustConfigurationReasonThe reason that the configuration of a native trust source is not valid.
EmptyRoot#
EmptyRootA root file path is empty.
NonAbsoluteRoot#
NonAbsoluteRootA root file path is not absolute.
NulRoot#
NulRootA root file path contains a zero byte.
PathBytes#
PathBytesA root file path is too long.
Implementation Debug for TrustConfigurationReason#
impl Debug for TrustConfigurationReasonOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the variant, such as EmptyRoot.
TrustFileOperation#
pub enum TrustFileOperationThe file step that failed in a native trust source.
Open#
OpenOpening the trust file.
Read#
ReadReading the trust file.
Close#
CloseClosing the trust file.
Implementation Debug for TrustFileOperation#
impl Debug for TrustFileOperationOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the variant, such as Open.
TrustSourceError#
pub union TrustSourceErrorThe reason that loading trust failed. An allocation failure is an OutOfMemoryError instead.
Decode#
DecodeA certificate or its PEM is not valid.
Field error#
pub error: DecodeErrorThe decoder error, with its position.
LimitExceeded#
LimitExceededA limit was exceeded.
Field kind#
pub kind: TrustLimitKindThe limit.
Field limit#
pub limit: usizeThe value of the limit.
InvalidConfiguration#
InvalidConfigurationThe configuration of a native trust source is not valid.
Field reason#
pub reason: TrustConfigurationReasonThe problem.
File#
FileA file operation of a native trust source failed.
Field operation#
pub operation: TrustFileOperationThe step that failed.
Field error#
pub error: FileErrorThe file error.
Implementation Debug for TrustSourceError#
impl Debug for TrustSourceErrorOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the variant and its fields, such as Decode { ... }.
TrustSnapshot#
pub struct TrustSnapshotA list of trust anchors that does not change. It owns them and keeps their order and duplicates.
When to use#
Make one from your CA certificates with TrustSnapshot.fromPem, or from anchors with limits
with TrustSnapshot.fromAnchors. Pass it to path validation or to a TLS client. Use
TrustSnapshot.combine to add your own CAs to another snapshot.
Details#
SnapshotLimits and TrustLoadLimits bound its size. An empty snapshot is valid: it trusts
no certificate.
Gotchas#
A snapshot is only a list of authorities. It does not check chains, names, dates, or revocation, and it is not the trust store of the operating system.
Implementation TrustSnapshot#
impl TrustSnapshotAssociated function fromAnchors#
pub fn fromAnchors(
anchors: List<TrustAnchor>,
limits: SnapshotLimits,
) -> Result<TrustSnapshot, TrustSourceError>Returns a snapshot with anchors, in their order. It does not copy them.
An empty list is valid.
Errors#
LimitExceededifanchorsgoes overlimits. The anchors are dropped.
Associated function fromPem#
pub effect fn fromPem(
input: &[u8],
limits: TrustLoadLimits,
) -> Result<TrustSnapshot, TrustSourceError>
! OutOfMemoryError
? &mut AllocatorReturns a snapshot with one anchor without limits for each CERTIFICATE block of input.
Errors#
FailurewithDecodeif the PEM or a certificate is not valid. The decoder is strict, and an empty file is an error.FailurewithLimitExceededif a limit is exceeded.OutOfMemoryErrorif theAllocatorfails.
Associated function fromAnnotatedPem#
pub effect fn fromAnnotatedPem(input: &[u8], limits: TrustLoadLimits) -> Result<TrustSnapshot, TrustSourceError>
! OutOfMemoryError ? &mut AllocatorReturns a snapshot from a CA file that has comment lines between the blocks.
It uses CertificateBundle.decodeAnnotatedPem. A certificate that is not valid fails the
whole call. None are skipped.
Errors#
The same errors as
TrustSnapshot.fromPem.
Gotchas#
Use it only for a CA file that you configured and trust, never for data from a peer.
Method anchors#
pub fn anchors(self: &Self) -> &[TrustAnchor]Returns the anchors in their order, with duplicates.
Method copy#
pub effect fn copy(
self: &Self,
limits: SnapshotLimits,
) -> Result<TrustSnapshot, TrustSourceError>
! OutOfMemoryError
? &mut AllocatorReturns a copy of the snapshot that is checked against limits.
Errors#
FailurewithLimitExceededif the snapshot goes overlimits.OutOfMemoryErrorif theAllocatorfails.
Associated function combine#
pub effect fn combine(
primary: &TrustSnapshot,
additional: &TrustSnapshot,
limits: SnapshotLimits,
) -> Result<TrustSnapshot, TrustSourceError>
! OutOfMemoryError
? &mut AllocatorReturns a new snapshot with the anchors of primary and then those of additional.
Duplicates are kept. Equal certificates are not merged.
Errors#
FailurewithLimitExceededif the result goes overlimits.OutOfMemoryErrorif theAllocatorfails.
Gotchas#
An anchor in additional with fewer limits than the same certificate in primary makes the
trust wider.
Category: TLS and certificates.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.