Struct DigestUtils

Source
pub struct DigestUtils;
Expand description

Utilities for working with SHA256 digests in Docker context

Implementations§

Source§

impl DigestUtils

Source

pub fn compute_sha256(data: &[u8]) -> String

Compute SHA256 digest from byte data

注意:Docker 镜像层的 digest 必须基于 gzip 压缩后的 tar 字节流计算。 传入 data 必须是 gzip 字节流,否则会导致 digest 校验失败。

Source

pub fn compute_sha256_str(data: &str) -> String

Compute SHA256 digest from string data

Source

pub fn compute_docker_digest(data: &[u8]) -> String

Compute full Docker digest (with sha256: prefix) from byte data

注意:Docker 镜像层的 digest 必须基于 gzip 压缩后的 tar 字节流计算。 传入 data 必须是 gzip 字节流,否则会导致 digest 校验失败。

Source

pub fn compute_docker_digest_str(data: &str) -> String

Compute full Docker digest (with sha256: prefix) from string data

Source

pub fn is_valid_sha256_hex(digest: &str) -> bool

Validate SHA256 hex string (64 characters, all hex)

Source

pub fn is_valid_docker_digest(digest: &str) -> bool

Validate full Docker digest format (sha256:xxxxx)

Source

pub fn normalize_digest(digest: &str) -> Result<String>

Normalize digest to full Docker format (add sha256: prefix if missing)

Source

pub fn extract_hex_part(digest: &str) -> Result<&str>

Extract SHA256 hex part from full Docker digest

Source

pub fn is_empty_layer_digest(digest: &str) -> bool

Check if a digest represents an empty layer

Source

pub fn empty_layer_digest() -> String

Get the standard empty layer digest with full Docker format

Source

pub fn verify_data_integrity(data: &[u8], expected_digest: &str) -> Result<()>

Verify data matches expected digest

注意:Docker 镜像层的 digest 校验必须基于 gzip 压缩后的 tar 字节流。 传入 data 必须是 gzip 字节流,否则会导致校验失败。

Source

pub async fn verify_stream_integrity<R>( reader: R, expected_digest: &str, ) -> Result<Vec<u8>>
where R: AsyncRead + Unpin,

Verify data integrity by computing digest on the fly from a stream

注意:Docker 镜像层的 digest 校验必须基于 gzip 压缩后的 tar 字节流。 传入 reader 必须输出 gzip 字节流,否则会导致校验失败。

Source

pub fn extract_digest_from_layer_path(layer_path: &str) -> Option<String>

Extract digest from Docker layer path (various formats)

Source

pub fn generate_path_based_digest(layer_path: &str) -> String

Generate a fallback digest from path when real digest cannot be extracted

Source

pub fn format_digest_short(digest: &str) -> String

Format digest for display (truncated for readability)

Source

pub fn validate_digests(digests: &[&str]) -> Result<()>

Batch validate multiple digests

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,