--- name: Digest::MD5 runtime: pp source: src/native/Digest/MD5/pp.rs --- ```{index} single: Digest::MD5; Perl module (pp runtime) ``` # Digest::MD5 Native implementation of Digest::MD5 Provides MD5 hashing functionality compatible with the Digest::MD5 Perl module. # Synopsis use Digest::MD5 qw(md5_hex md5_base64); my $hex = md5_hex("some data"); my $base64 = md5_base64("some data"); # OO interface for incremental hashing my $ctx = Digest::MD5->new; $ctx->add("first chunk"); $ctx->add("second chunk"); my $digest = $ctx->hexdigest; # Functional Interface - `md5($data)` - Returns binary MD5 digest (16 bytes) - `md5_hex($data)` - Returns hexadecimal MD5 digest (32 characters) - `md5_base64($data)` - Returns base64-encoded MD5 digest (22 characters, no padding) # Object-Oriented Interface - `Digest::MD5->new()` - Creates a new MD5 context object - `$ctx->add($data, ...)` - Adds data to the context - `$ctx->addfile($fh)` - Adds data from a filehandle (not yet implemented) - `$ctx->digest()` - Returns binary digest and resets the context - `$ctx->hexdigest()` - Returns hex digest and resets the context - `$ctx->b64digest()` - Returns base64 digest (no padding) and resets the context - `$ctx->reset()` - Resets the context - `$ctx->clone()` - Clones the context # Implementation Notes The OO interface stores accumulated data in a blessed hash reference. The hash uses a special key `_data` to store the accumulated bytes. Computing the actual MD5 hash is done when `digest()`, `hexdigest()`, or `b64digest()` is called. This approach avoids the complexity of storing Rust state (Md5 hasher) in Perl values while maintaining compatibility with the Perl interface.