[][src]Struct asuran::repository::Chunk

pub struct Chunk {
    data: Vec<u8>,
    compression: Compression,
    encryption: Encryption,
    hmac: HMAC,
    mac: Vec<u8>,
    id: ChunkID,

A binary blob, ready to be commited to storage

A Chunk is an arbitrary sequence of bytes, along with its associated ChunkID key.

Data in a Chunk has already undergone any selected compression and encryption, and has an associated HMAC tag used for verifying the integrity of the data. This HMAC tag is unrelated to the ChunkID key, and uses a separate HMAC key.

Chunks are additionally tagged with the encryption and compression modes used for them.


data: Vec<u8>

The data of the chunk, stored as a vec of raw bytes

compression: Compression

Compression algorithim used

encryption: Encryption

Encryption Algorithim used, also stores IV

hmac: HMAC

HMAC algorithim used

mac: Vec<u8>

HMAC tag of the cyphertext bytes of this chunk

id: ChunkID

ChunkID, used for indexing in the repository and deduplication


impl Chunk[src]

pub fn pack(
    data: Vec<u8>,
    compression: Compression,
    encryption: Encryption,
    hmac: HMAC,
    key: &Key
) -> Chunk

Produces a Chunk from the given data, using the specified encryption, and hmac algorithms, as well as the supplied key material.


Will panic if any of the compression, encryption, or HMAC operations fail. This would represent a massive programming oversight which the user of the library has little hope of recovering from safely without compromising cryptographic integrity.

pub fn from_parts(
    data: Vec<u8>,
    compression: Compression,
    encryption: Encryption,
    hmac: HMAC,
    mac: Vec<u8>,
    id: ChunkID
) -> Chunk

Constructs a Chunk from its raw parts.

This has potentially dangerous consequences if done incorrectly, and should be avoided if another method is available.

pub fn pack_with_id(
    data: Vec<u8>,
    compression: Compression,
    encryption: Encryption,
    hmac: HMAC,
    key: &Key,
    id: ChunkID
) -> Chunk

Produces a Chunk using the provided settings, but overriding the ChunkID key.

This has the potential to do serious damage to a repository if used incorrectly, and should be avoided if another method is available.

pub fn unpack(&self, key: &Key) -> Result<Vec<u8>, ChunkError>[src]

Validates, decrypts, and decompresses the data in a Chunk.


Will return Err(HMACVailidationFailed) if the chunk fails validation.

Will return Err(EncryptionError) if decryption fails.

Will return Err(CompressionError) if decompression fails.

All of these error values indicate that the Chunk is corrupted or otherwise malformed.

pub fn len(&self) -> usize[src]

Returns the length of the data in the Chunk

pub fn is_empty(&self) -> bool[src]

Determine if this chunk is empty

pub fn get_bytes(&self) -> &[u8][src]

Returns a reference to the raw bytes of this chunk

pub fn get_id(&self) -> ChunkID[src]

Returns the ChunkID key assocaited with the data in this chunk.

pub fn mac(&self) -> Vec<u8>[src]

Returns the mac value of this chunk

pub fn split(self) -> (ChunkHeader, ChunkBody)[src]

Splits a Chunk into its header and body components

pub fn unsplit(header: ChunkHeader, body: ChunkBody) -> Chunk[src]

Combines a header and a body into a Chunk

pub fn encryption(&self) -> Encryption[src]

Returns a copy of the encryption method/iv used for the chunk

Trait Implementations

impl Clone for Chunk[src]

impl Debug for Chunk[src]

impl<'de> Deserialize<'de> for Chunk[src]

impl Eq for Chunk[src]

impl PartialEq<Chunk> for Chunk[src]

impl Serialize for Chunk[src]

Auto Trait Implementations

impl RefUnwindSafe for Chunk

impl Send for Chunk

impl Sync for Chunk

impl Unpin for Chunk

impl UnwindSafe for Chunk

Blanket Implementations

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

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

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

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]