| 1 | package SBOM::CycloneDX::Hash; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use SBOM::CycloneDX::Enum; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Types::Standard qw(Enum StrMatch); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | extends 'SBOM::CycloneDX::Base'; | |||||||||
| 16 | |||||||||||
| 17 | 2 | 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 | 2 | has alg => (is => 'rw', isa => Enum [SBOM::CycloneDX::Enum->values('HASH_ALGORITHM')], required => 1); | |||||||||
| 35 | |||||||||||
| 36 | 2 | 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 | 8 | ▶ | sub _trigger_content { | ||||||||
|
Subroutine
_trigger_content: called CC=2 SCAR=7.6
| |||||||||||
| 44 | 8 | ▶ | Carp::croak 'Invalid hash length' if $ALGO_LENGTH{$_[0]->alg} != length($_[0]->content); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 24 | ▶ | sub TO_JSON { | ||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 48 | |||||||||||
| 49 | 24 | my $self = shift; | |||||||||
| 50 | |||||||||||
| 51 | 24 | my $json = {alg => $self->alg, content => $self->content}; | |||||||||
| 52 | |||||||||||
| 53 | 24 | return $json; | |||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | 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<SBOM::CycloneDX::Hash> provides the hash object. | ||||||||||
| 73 | |||||||||||
| 74 | =head2 METHODS | ||||||||||
| 75 | |||||||||||
| 76 | L<SBOM::CycloneDX::Hash> inherits all methods from L<SBOM::CycloneDX::Base> | ||||||||||
| 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<alg>, The algorithm that generated the hash value. | ||||||||||
| 88 | |||||||||||
| 89 | =item * C<content>, 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<https://github.com/giterlizzi/perl-SBOM-CycloneDX/issues>. | ||||||||||
| 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<https://github.com/giterlizzi/perl-SBOM-CycloneDX> | ||||||||||
| 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 <gdt@cpan.org> | ||||||||||
| 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 | ||||||||||