File Coverage

blib/lib/SBOM/CycloneDX/Hash.pm
Criterion Covered Total %
statement 27 27 100.0
branch 1 2 50.0
condition n/a
subroutine 10 10 100.0
pod 1 1 100.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             package SBOM::CycloneDX::Hash;
2              
3 2     2   2020 use 5.010001;
  2         12  
4 2     2   14 use strict;
  2         3  
  2         77  
5 2     2   10 use warnings;
  2         5  
  2         146  
6 2     2   24 use utf8;
  2         5  
  2         28  
7              
8 2     2   123 use SBOM::CycloneDX::Enum;
  2         5  
  2         126  
9              
10 2     2   13 use Types::Standard qw(Enum StrMatch);
  2         4  
  2         18  
11              
12 2     2   5883 use Moo;
  2         5  
  2         17  
13 2     2   950 use namespace::autoclean;
  2         5  
  2         17  
14              
15             extends 'SBOM::CycloneDX::Base';
16              
17             my %ALGO_LENGTH = (
18             'MD5' => 32,
19             'SHA-1' => 40,
20             'SHA-256' => 64,
21             'SHA-384' => 96,
22             'SHA-512' => 128,
23             'SHA3-256' => 64,
24             'SHA3-384' => 96,
25             'SHA3-512' => 128,
26             'BLAKE2b-256' => 64,
27             'BLAKE2b-384' => 96,
28             'BLAKE2b-512' => 128,
29             'BLAKE3' => 64,
30             'Streebog-256' => 64,
31             'Streebog-512' => 128,
32             );
33              
34             has alg => (is => 'rw', isa => Enum [SBOM::CycloneDX::Enum->values('HASH_ALGORITHM')], required => 1);
35              
36             has content => (
37             is => 'rw',
38             isa => StrMatch [qr{^([a-fA-F0-9]{32}|[a-fA-F0-9]{40}|[a-fA-F0-9]{64}|[a-fA-F0-9]{96}|[a-fA-F0-9]{128})$}],
39             required => 1,
40             trigger => 1
41             );
42              
43             sub _trigger_content {
44 8 50   8   16712 Carp::croak 'Invalid hash length' if $ALGO_LENGTH{$_[0]->alg} != length($_[0]->content);
45             }
46              
47             sub TO_JSON {
48              
49 104     104 1 283 my $self = shift;
50              
51 104         1894 my $json = {alg => $self->alg, content => $self->content};
52              
53 104         3038 return $json;
54              
55             }
56              
57             1;
58              
59             =encoding utf-8
60              
61             =head1 NAME
62              
63             SBOM::CycloneDX::Hash - Hash
64              
65             =head1 SYNOPSIS
66              
67             SBOM::CycloneDX::Hash->new();
68              
69              
70             =head1 DESCRIPTION
71              
72             L provides the hash object.
73              
74             =head2 METHODS
75              
76             L inherits all methods from L
77             and implements the following new ones.
78              
79             =over
80              
81             =item SBOM::CycloneDX::Hash->new( %PARAMS )
82              
83             Properties:
84              
85             =over
86              
87             =item * C, The algorithm that generated the hash value.
88              
89             =item * C, The value of the hash.
90              
91             =back
92              
93             =item $hash->_trigger_content
94              
95             =item $hash->alg
96              
97             =item $hash->content
98              
99             =back
100              
101              
102             =head1 SUPPORT
103              
104             =head2 Bugs / Feature Requests
105              
106             Please report any bugs or feature requests through the issue tracker
107             at L.
108             You will be notified automatically of any progress on your issue.
109              
110             =head2 Source Code
111              
112             This is open source software. The code repository is available for
113             public review and contribution under the terms of the license.
114              
115             L
116              
117             git clone https://github.com/giterlizzi/perl-SBOM-CycloneDX.git
118              
119              
120             =head1 AUTHOR
121              
122             =over 4
123              
124             =item * Giuseppe Di Terlizzi
125              
126             =back
127              
128              
129             =head1 LICENSE AND COPYRIGHT
130              
131             This software is copyright (c) 2025-2026 by Giuseppe Di Terlizzi.
132              
133             This is free software; you can redistribute it and/or modify it under
134             the same terms as the Perl 5 programming language system itself.
135              
136             =cut