CodeResourcesBuilder

Struct CodeResourcesBuilder 

Source
pub struct CodeResourcesBuilder { /* private fields */ }
Expand description

Builder for generating CodeResources plist files.

This builder scans an iOS/macOS app bundle, computes cryptographic hashes (SHA-1 and SHA-256) of all files, and produces the CodeResources plist required for code signing.

§Builder Pattern

use zsign::bundle::CodeResourcesBuilder;

let plist = CodeResourcesBuilder::new("/path/to/App.app")
    .exclude("DebugResources/")
    .scan()?
    .build()?;

§Automatic Exclusions

The builder automatically excludes:

  • _CodeSignature/ directory (contains the signature itself)
  • The main executable specified in Info.plist (has embedded signature)

Implementations§

Source§

impl CodeResourcesBuilder

Source

pub fn new(bundle_path: impl AsRef<Path>) -> Self

Creates a new CodeResourcesBuilder for the given bundle path.

Automatically reads Info.plist to determine the main executable (which is excluded from hashing as it has an embedded signature).

§Examples
use zsign::bundle::CodeResourcesBuilder;

let builder = CodeResourcesBuilder::new("/path/to/MyApp.app");
Source

pub fn exclude(self, pattern: impl Into<String>) -> Self

Adds a custom exclusion pattern.

Files with paths starting with this pattern will be excluded from hashing.

§Examples
use zsign::bundle::CodeResourcesBuilder;

let builder = CodeResourcesBuilder::new("/path/to/App.app")
    .exclude("DebugResources/")
    .exclude("TestData/");
Source

pub fn scan(&mut self) -> Result<&mut Self>

Scans the bundle directory and hashes all files.

Walks the bundle directory tree, computes SHA-1 and SHA-256 hashes for each file (excluding directories and excluded paths), and stores them for later plist generation.

Files are processed in parallel using rayon for performance.

§Errors

Returns an error if:

  • The bundle directory cannot be read
  • A file cannot be read for hashing
  • Symlink targets cannot be resolved (on Unix)
§Examples
use zsign::bundle::CodeResourcesBuilder;

let mut builder = CodeResourcesBuilder::new("/path/to/App.app");
builder.scan()?;
println!("Scanned {} files", builder.file_count());
Source

pub fn hash_data(data: &[u8]) -> ([u8; 20], [u8; 32])

Computes SHA-1 and SHA-256 hashes of the given data.

Utility method for hashing arbitrary byte slices.

§Examples
use zsign::bundle::CodeResourcesBuilder;

let (sha1, sha256) = CodeResourcesBuilder::hash_data(b"Hello, World!");
assert_eq!(sha1.len(), 20);
assert_eq!(sha256.len(), 32);
Source

pub fn add_file( &mut self, relative_path: impl Into<String>, sha1: [u8; 20], sha256: [u8; 32], )

Adds a file entry manually with pre-computed hashes.

Useful for adding files with known hashes without reading from disk, such as nested bundle CodeResources files.

§Examples
use zsign::bundle::CodeResourcesBuilder;

let mut builder = CodeResourcesBuilder::new("/path/to/App.app");
let (sha1, sha256) = CodeResourcesBuilder::hash_data(b"file content");
builder.add_file("Resources/data.bin", sha1, sha256);
Source

pub fn add_optional_file( &mut self, relative_path: impl Into<String>, sha1: [u8; 20], sha256: [u8; 32], )

Adds an optional file entry with pre-computed hashes.

Optional files are marked in the plist and may be missing from the bundle without invalidating the signature. Commonly used for localization files.

Source

pub fn build(&self) -> Result<Vec<u8>>

Builds the CodeResources plist as XML bytes.

Generates the complete _CodeSignature/CodeResources plist containing:

  • files: Legacy SHA-1 hashes for older iOS versions
  • files2: Modern SHA-1 + SHA-256 hashes with metadata
  • rules / rules2: Standard Apple inclusion/exclusion patterns
§Errors

Returns an error if plist serialization fails.

§Examples
use zsign::bundle::CodeResourcesBuilder;

let mut builder = CodeResourcesBuilder::new("/path/to/App.app");
builder.scan()?;
let plist_bytes = builder.build()?;
std::fs::write("/path/to/App.app/_CodeSignature/CodeResources", plist_bytes)?;
Source

pub fn files(&self) -> impl Iterator<Item = (&String, &[u8; 20], &[u8; 32])>

Returns an iterator over all scanned files and their hashes.

Each item contains the relative path, SHA-1 hash, and SHA-256 hash.

Source

pub fn file_count(&self) -> usize

Returns the number of files that will be included in the plist.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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