| 1 | package Crypt::Perl::X509::GeneralNames; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use parent qw( Crypt::Perl::ASN1::Encodee ); | ||
| 7 | |||
| 8 | use Crypt::Perl::X509::GeneralName (); | ||
| 9 | |||
| 10 | use constant ASN1 => Crypt::Perl::X509::GeneralName::ASN1() . <<END; | ||
| 11 | GeneralNames ::= SEQUENCE OF ANY -- GeneralName | ||
| 12 | END | ||
| 13 | |||
| 14 | sub new { | ||
| 15 | my ($class, @type_vals) = @_; | ||
| 16 | |||
| 17 | my @sequence; | ||
| 18 | |||
| 19 | # Accept either pairs of two-member arrays (new, preferred format) | ||
| 20 | # or flat key/value pairs. | ||
| 21 | while (@type_vals) { | ||
| 22 | if ('ARRAY' eq ref $type_vals[0]) { | ||
| 23 | push @sequence, shift @type_vals; | ||
| 24 | } | ||
| 25 | elsif ( !ref $type_vals[0] ) { | ||
| 26 | push @sequence, [ shift(@type_vals) => shift(@type_vals) ]; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | return bless \@sequence, $class; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub _encode_params { | ||
| 34 | my ($self) = @_; | ||
| 35 | |||
| 36 | my @params = @$self; | ||
| 37 | $_ = Crypt::Perl::X509::GeneralName->new(@$_) for @params; | ||
| 38 | |||
| 39 | return [ map { $_->encode() } @params ]; | ||
| 40 | } | ||
| 41 | |||
| 42 | 1; |