« blib/lib/Crypt/Perl/X509/Extension/authorityKeyIdentifier.pm
↑ Summary
blib/lib/Crypt/Perl/X509/Extension/basicConstraints.pm »
| 1 | package Crypt::Perl::PKCS10::Attributes; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | =encoding utf-8 | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Crypt::Perl::PKCS10::Attributes - CSR “attributes” collection | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | #Each object passed should be an instance of a subclass of | ||
| 15 | #Crypt::Perl::PKCS10::Attribute (NB: not this class!) | ||
| 16 | my $attrs = Crypt::Perl::PKCS10::Attributes->new( @ATTR_OBJS ); | ||
| 17 | |||
| 18 | #...or: | ||
| 19 | |||
| 20 | my $attrs = Crypt::Perl::PKCS10::Attributes->new( | ||
| 21 | [ $attr_type1 => \@args1 ], | ||
| 22 | [ $attr_type2 => \@args2 ], | ||
| 23 | ); | ||
| 24 | |||
| 25 | #...for example: | ||
| 26 | |||
| 27 | my $attrs = Crypt::Perl::PKCS10::Attributes->new( | ||
| 28 | [ challengePassword => 'iNsEcUrE' ], | ||
| 29 | ); | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | Instances of this class represent the “attributes” collection in a | ||
| 34 | PKCS #10 Certificate Signing Request. | ||
| 35 | |||
| 36 | You probably don’t need to | ||
| 37 | instantiate this class directly; instead, you can instantiate it | ||
| 38 | implicitly by listing out arguments to | ||
| 39 | L<Crypt::Perl::PKCS10>’s constructor. See that module’s | ||
| 40 | L<SYNOPSIS|Crypt::Perl::PKCS10/SYNOPSIS> for an example. | ||
| 41 | |||
| 42 | The following X.509 extensions are supported: | ||
| 43 | |||
| 44 | =over 4 | ||
| 45 | |||
| 46 | =item * L<extensionRequest|Crypt::Perl::X509::Attribute::extensionRequest> | ||
| 47 | |||
| 48 | =item * L<challengePassword|Crypt::Perl::X509::Attribute::challengePassword> | ||
| 49 | (Note that this attribute does B<NOT> encrypt anything; don’t encode any | ||
| 50 | values that are sensitive data!) | ||
| 51 | |||
| 52 | =back | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | use Try::Tiny; | ||
| 57 | |||
| 58 | use Crypt::Perl::X (); | ||
| 59 | |||
| 60 | use parent qw( | ||
| 61 | Crypt::Perl::ASN1::Encodee | ||
| 62 | ); | ||
| 63 | |||
| 64 | use constant ASN1 => <<END; | ||
| 65 | Attributes ::= SET OF Attribute | ||
| 66 | Attribute ::= SEQUENCE { | ||
| 67 | type OBJECT IDENTIFIER, | ||
| 68 | values SET OF ANY | ||
| 69 | } | ||
| 70 | END | ||
| 71 | |||
| 72 | my $ATTR_BASE = 'Crypt::Perl::PCKS10::Attribute'; | ||
| 73 | |||
| 74 | sub new { | ||
| 75 | my ($class, @attrs) = @_; | ||
| 76 | |||
| 77 | for my $attr (@attrs) { | ||
| 78 | if (!try { $attr->isa($ATTR_BASE) }) { | ||
| 79 | if ( 'ARRAY' eq ref $attr ) { | ||
| 80 | my $module = $attr->[0]; | ||
| 81 | my $class = "Crypt::Perl::PKCS10::Attribute::$module"; | ||
| 82 | Module::Load::load($class); | ||
| 83 | $attr = $class->new( @{$attr}[ 1 .. $#$attr ] ); | ||
| 84 | } | ||
| 85 | else { | ||
| 86 | die Crypt::Perl::X::create('Generic', "Attribute must be ARRAY reference or instance of $ATTR_BASE, not “$attr”!"); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | return bless \@attrs, $class; | ||
| 92 | } | ||
| 93 | |||
| 94 | *structure = \&_encode_params; | ||
| 95 | |||
| 96 | sub _encode_params { | ||
| 97 | my ($self) = @_; | ||
| 98 | |||
| 99 | return [ | ||
| 100 | map { | ||
| 101 | { | ||
| 102 | type => $_->OID(), | ||
| 103 | values => [ $_->encode() ], | ||
| 104 | }, | ||
| 105 | } @$self | ||
| 106 | ]; | ||
| 107 | } | ||
| 108 | |||
| 109 | 1; |