File: 99misc.t

package info (click to toggle)
libconvert-asn1-perl 0.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: perl: 4,526; yacc: 544; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/local/bin/perl

#
# Misc tests from github reported issues
#

use Convert::ASN1;
BEGIN { require './t/funcs.pl' }

print "1..2\n";

{    # github issue 8

  my $hexdata = "30 53 30 51 30 4f 30 4d 30 4b 30 09 06 05 2b 0e
                 03 02 1a 05 00 04 14 a0 72 0e a0 6a 7c 62 02 54
                 f2 a8 f5 9d d2 7b a4 f3 b7 2f a4 04 14 b0 b0 4a
                 fd 1c 75 28 f8 1c 61 aa 13 f6 fa c1 90 3d 6b 16
                 a3 02 12 11 21 bc 57 28 6f 30 08 db 49 63 f6 ae
                 89 3a de f6 d1 ff e0";
  $hexdata =~ s/ //g;
  $hexdata =~ s/\n//g;

# parse ASN.1 descriptions
  my $asn = Convert::ASN1->new;
  $asn->prepare(<<ASN1) or die "prepare: ", $asn->error;
  OCSPRequest     ::=     SEQUENCE {
      tbsRequest                  TBSRequest,
      optionalSignature   [0]     EXPLICIT ANY OPTIONAL }

  TBSRequest      ::=     SEQUENCE {
      version             [0]     EXPLICIT INTEGER OPTIONAL,
      requestorName       [1]     EXPLICIT ANY OPTIONAL,
      requestList                 SEQUENCE OF Request,
      requestExtensions   [2]     EXPLICIT ANY OPTIONAL }

  Request         ::=     SEQUENCE {
      reqCert                     CertID,
      singleRequestExtensions     [0] EXPLICIT ANY OPTIONAL }

  CertID          ::=     SEQUENCE {
      hashAlgorithm       ANY,
      issuerNameHash      OCTET STRING, -- Hash of Issuer's DN
      issuerKeyHash       OCTET STRING, -- Hash of Issuers public key
      serialNumber        INTEGER }
ASN1

  my $asn_ocspreq = $asn->find('OCSPRequest');

  my $OCSPREQDER = pack("H*", $hexdata);

  my $ocspreq = $asn_ocspreq->decode($OCSPREQDER);
  my $err = $asn_ocspreq->error;
  $err =~ s/ at .*line \d.*//s if $err;
  stest 1, "decode error 85 87", $err;

  btest 2, !!$asn_ocspreq->decode(substr($OCSPREQDER, 0, -2));

}