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
impl CodeResourcesBuilder
Sourcepub fn new(bundle_path: impl AsRef<Path>) -> Self
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");Sourcepub fn exclude(self, pattern: impl Into<String>) -> Self
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/");Sourcepub fn scan(&mut self) -> Result<&mut Self>
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());Sourcepub fn hash_data(data: &[u8]) -> ([u8; 20], [u8; 32])
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);Sourcepub fn add_file(
&mut self,
relative_path: impl Into<String>,
sha1: [u8; 20],
sha256: [u8; 32],
)
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);Sourcepub fn add_optional_file(
&mut self,
relative_path: impl Into<String>,
sha1: [u8; 20],
sha256: [u8; 32],
)
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.
Sourcepub fn build(&self) -> Result<Vec<u8>>
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 versionsfiles2: Modern SHA-1 + SHA-256 hashes with metadatarules/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)?;Sourcepub fn files(&self) -> impl Iterator<Item = (&String, &[u8; 20], &[u8; 32])>
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.
Sourcepub fn file_count(&self) -> usize
pub fn file_count(&self) -> usize
Returns the number of files that will be included in the plist.
Auto Trait Implementations§
impl Freeze for CodeResourcesBuilder
impl RefUnwindSafe for CodeResourcesBuilder
impl Send for CodeResourcesBuilder
impl Sync for CodeResourcesBuilder
impl Unpin for CodeResourcesBuilder
impl UnwindSafe for CodeResourcesBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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