silk.tls.trust_source_memory.
A TrustSource provider that holds a trust snapshot in memory.
When to use#
Use MemoryTrustSource when the program already has its trust anchors, for example from an
embedded CA file, and in tests. Call MemoryTrustSource.replace to change the trust for later
loads, for example after a configuration reload.
Details#
Each load returns a copy of the current snapshot. Snapshots that were loaded before a replacement do not change.
Gotchas#
It does not read files, refresh, or remove duplicates.
Examples#
Provide trust from memory#
import silk.mem.allocator { Allocator, OutOfMemoryError }
import silk.core.effect { Effect }
import silk.collections.list { List }
import silk.tls.trust_source_memory { MemoryTrustSource }
import silk.core.result { Result }
import silk.tls.trust_anchor { TrustAnchor }
import silk.tls.trust_snapshot { SnapshotLimits, TrustLoadLimits, TrustSnapshot, TrustSourceError }
import silk.tls.trust_source { TrustSource }
pub effect fn main() -> i32
! TrustSourceError | OutOfMemoryError {
let mut allocator = Allocator.systemAllocatorProvider()
let snapshot = match TrustSnapshot.fromAnchors(
List<TrustAnchor>.make(),
SnapshotLimits.defaults()
) {
Result<TrustSnapshot, TrustSourceError>.Success { value } => move value
Result<TrustSnapshot, TrustSourceError>.Failure { error: _ } => {
return 1
}
}
let mut source = MemoryTrustSource.make(move snapshot)
let loaded = run TrustSource.load(TrustLoadLimits.defaults())
|> Effect.provideMut<TrustSource>(&mut source)
|> Effect.provideMut<Allocator>(&mut allocator)
if TrustSnapshot.anchors(&loaded).length != 0 {
return 1
}
return 0
}Import as MemoryTrustSource with import silk.tls.trust_source_memory { MemoryTrustSource }.
Public declarations: 1.
MemoryTrustSource#
pub struct MemoryTrustSourceA TrustSource provider that owns the current trust snapshot in memory.
When to use#
Use it when the program already has its trust anchors, for example from an embedded CA file, and
in tests. Call MemoryTrustSource.replace to change the trust for later loads, for example
after a configuration reload.
Details#
Each load returns a copy of the current snapshot. Snapshots that were loaded before a replacement do not change.
Gotchas#
It does not read files, refresh, or remove duplicates.
Implementation MemoryTrustSource#
impl MemoryTrustSourceAssociated function make#
pub fn make(snapshot: TrustSnapshot) -> MemoryTrustSourceReturns a provider with snapshot as the current trust. It does not allocate or check the
snapshot.
Method replace#
pub fn replace(self: &mut Self, next: TrustSnapshot) -> TrustSnapshotMakes next the current trust, and returns the old snapshot.
Only later loads see next. Snapshots that were loaded before do not change. It does not
allocate or fail.
Implementation TrustSource for MemoryTrustSource#
impl TrustSource for MemoryTrustSourceOperation load#
load: MemoryTrustSource.loadCurrentCategory: 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.