Crypt-TimestampedData
view release on metacpan or search on metacpan
METHODS
new(%args)
Creates a new Crypt::TimestampedData object with the provided
arguments.
read_file($filepath)
Reads and decodes a .TSD file from the specified path. Returns a hash
reference containing the decoded TimeStampedData structure.
write_file($filepath, $tsd_hashref)
Encodes and writes a TimeStampedData structure to the specified file
path.
decode_der($der)
Decodes DER-encoded TimeStampedData. Handles both direct TSD format and
CMS ContentInfo wrappers (id-ct-TSTData and pkcs7-signedData).
lib/Crypt/TimestampedData.pm view on Meta::CPAN
=head1 METHODS
=head2 new(%args)
Creates a new Crypt::TimestampedData object with the provided arguments.
=head2 read_file($filepath)
Reads and decodes a .TSD file from the specified path. Returns a hash reference
containing the decoded TimeStampedData structure.
=head2 write_file($filepath, $tsd_hashref)
Encodes and writes a TimeStampedData structure to the specified file path.
=head2 decode_der($der)
Decodes DER-encoded TimeStampedData. Handles both direct TSD format and
CMS ContentInfo wrappers (id-ct-TSTData and pkcs7-signedData).
lib/Crypt/TimestampedData.pm view on Meta::CPAN
sub new {
my ($class, %args) = @_;
my $self = {%args};
return bless $self, $class;
}
sub decode_der {
my ($class, $der) = @_;
# Try direct TimeStampedData first
my $decoded = $TSD_CODEC->decode($der);
return $decoded if defined $decoded;
# If that fails, try unwrapping CMS ContentInfo (common packaging for TSD)
my $ci = $CONTENTINFO_CODEC->decode($der);
die 'ASN.1 decode failed: ' . $TSD_CODEC->error unless defined $ci;
# Two acceptable wrappings for RFC 5544:
# 1) ContentInfo with contentType id-ct-TSTData and [0] content = TimeStampedData
# 2) ContentInfo with contentType pkcs7-signedData, whose encapContentInfo.eContentType is id-ct-TSTData
my $content_der = $ci->{content};
t/01_basic.t view on Meta::CPAN
$extracted_content = Crypt::TimestampedData->extract_content_der($tsd_data)
} 'Extract content from TSD';
is($extracted_content, undef, 'No content to extract (as expected)');
# Test 5: Test DER encoding/decoding roundtrip
my $der;
lives_ok { $der = Crypt::TimestampedData->encode_der($tsd_data) } 'Encode TSD to DER';
ok(defined $der && length($der) > 0, 'DER encoding produced data');
my $decoded_tsd;
lives_ok { $decoded_tsd = Crypt::TimestampedData->decode_der($der) } 'Decode DER to TSD';
ok(defined $decoded_tsd, 'Decoded TSD is defined');
# Test 6: Verify roundtrip data integrity
is($decoded_tsd->{version}, $tsd_data->{version}, 'Version preserved in roundtrip');
is($decoded_tsd->{metaData}->{fileName}, $tsd_data->{metaData}->{fileName}, 'Filename preserved in roundtrip');
# Test 7: Test file operations
my $temp_dir = tempdir(CLEANUP => 1);
my $tsd_file = File::Spec->catfile($temp_dir, 'test.tsd');
lives_ok { Crypt::TimestampedData->write_file($tsd_file, $tsd_data) } 'Write TSD file';
ok(-f $tsd_file, 'TSD file created');
my $read_tsd;
lives_ok { $read_tsd = Crypt::TimestampedData->read_file($tsd_file) } 'Read TSD file';
t/05_regression.t view on Meta::CPAN
version => 1,
temporalEvidence => {
tstEvidence => []
}
};
my $empty_der;
lives_ok { $empty_der = Crypt::TimestampedData->encode_der($empty_tsd) } 'Encode empty TSD';
ok(defined $empty_der, 'Empty TSD encoded successfully');
my $decoded_empty;
lives_ok { $decoded_empty = Crypt::TimestampedData->decode_der($empty_der) } 'Decode empty TSD';
ok(defined $decoded_empty, 'Empty TSD decoded successfully');
# Test 2: TSD with minimal required fields
my $minimal_tsd = {
version => 1,
temporalEvidence => {
tstEvidence => [
{
timeStamp => {
contentType => '1.2.840.113549.1.7.1', # id-data
content => 'test_content'
t/06_alias.t view on Meta::CPAN
tstEvidence => []
}
};
# Test 4: Encode TSD to DER
my $der;
lives_ok { $der = Crypt::TSD->encode_der($tsd_data) } 'Encode TSD to DER using alias';
ok(defined $der && length($der) > 0, 'DER encoding produced data');
# Test 5: Decode DER back to TSD
my $decoded_tsd;
lives_ok { $decoded_tsd = Crypt::TSD->decode_der($der) } 'Decode DER to TSD using alias';
ok(defined $decoded_tsd, 'Decoded TSD is defined');
# Test 6: Verify roundtrip data integrity
is($decoded_tsd->{version}, $tsd_data->{version}, 'Version preserved in roundtrip');
is($decoded_tsd->{metaData}->{fileName}, $tsd_data->{metaData}->{fileName}, 'Filename preserved in roundtrip');
print "Crypt::TSD alias test completed successfully\n";
( run in 0.365 second using v1.01-cache-2.11-cpan-9383018d099 )