ActiveState!

ActivePerl Documentation
Table of Contents

(Usage Statistics)
(about this ver)


* Getting Started
    * Welcome To ActivePerl
    * Release Notes
    * Readme
    * ActivePerl Change Log
* Install Notes
    * Linux
    * Solaris
    * Windows
* ActivePerl Components
    * Overview
    * PPM
    * Windows Specifics
       * OLE Browser
       * PerlScript
       * Perl for ISAPI
       * PerlEZ
* ActivePerl FAQ
    * Introduction
    * Availability & Install
    * Using PPM
    * Docs & Support
    * Windows Specifics
       * Perl for ISAPI
       * Windows 9X/NT/2000
       * Quirks
       * Web Server Config
       * Web programming
       * Programming
       * Modules & Samples
       * Embedding & Extending
       * Using OLE with Perl
* Windows Scripting
    * Active Server Pages
    * Windows Script Host
    * Windows Script Components

Core Perl Documentation


* perl
* perlfaq
* perltoc
* perlbook

* perlsyn
* perldata
* perlop
* perlreftut
* perldsc
* perllol

* perllexwarn
* perldebug

* perlrun
* perlfunc
* perlopentut
* perlvar
* perlsub
* perlmod
* perlpod

* perlstyle
* perlmodlib
* perlmodinstall
* perltrap
* perlport
* perlsec

* perlref
* perlre
* perlform
* perllocale
* perlunicode

* perlboot
* perltoot
* perltootc
* perlobj
* perlbot
* perltie

* perlipc
* perlnumber
* perlfork
* perlthrtut

* perldiag
* perlfaq1
* perlfaq2
* perlfaq3
* perlfaq4
* perlfaq5
* perlfaq6
* perlfaq7
* perlfaq8
* perlfaq9

* perlcompile

* perlembed
* perlxstut
* perlxs
* perlguts
* perlcall
* perlfilter
* perldbmfilter
* perlapi
* perlintern
* perlapio
* perltodo
* perlhack

* perlhist
* perldelta
* perl5005delta
* perl5004delta

* perlamiga
* perlcygwin
* perldos
* perlhpux
* perlmachten
* perlos2
* perlos390
* perlvms
* perlwin32

Pragmas


* attributes
* attrs
* autouse
* base
* blib
* bytes
* charnames
* constant
* diagnostics
* fields
* filetest
* integer
* less
* lib
* locale
* lwpcook
* open
* ops
* overload
* perllocal
* re
* sigtrap
* strict
* subs
* utf8
* vars
* warnings

Libraries


* ActivePerl
    * DocTools
        * TOC
            * RDF
* AnyDBM_File
* Archive
    * Tar
* AutoLoader
* AutoSplit
* B
    * Asmdata
    * Assembler
    * Bblock
    * Bytecode
    * C
    * CC
    * Debug
    * Deparse
    * Disassembler
    * Lint
    * Showlex
    * Stackobj
    * Terse
    * Xref
* Benchmark
* Bundle
    * LWP
* ByteLoader
* Carp
    * Heavy
* CGI
    * Apache
    * Carp
    * Cookie
    * Fast
    * Pretty
    * Push
    * Switch
* Class
    * Struct
* Compress
    * Zlib
* Config
* CPAN
    * FirstTime
    * Nox
* Cwd
* Data
    * Dumper
* DB
* Devel
    * DProf
    * Peek
    * SelfStubber
* Digest
    * HMAC
    * HMAC_MD5
    * HMAC_SHA1
    * MD2
    * MD5
    * SHA1
* DirHandle
* Dumpvalue
* DynaLoader
* English
* Env
* Errno
* Exporter
    * Heavy
* ExtUtils
    * Command
    * Embed
    * Install
    * Installed
    * Liblist
    * MakeMaker
    * Manifest
    * Miniperl
    * Mkbootstrap
    * Mksymlists
    * MM_Cygwin
    * MM_OS2
    * MM_Unix
    * MM_VMS
    * MM_Win32
    * Packlist
    * testlib
* Fatal
* Fcntl
* File
    * Basename
    * CheckTree
    * Compare
    * Copy
    * CounterFile
    * DosGlob
    * Find
    * Glob
    * Listing
    * Path
    * Spec
        * Functions
        * Mac
        * OS2
        * Unix
        * VMS
        * Win32
    * stat
* FileCache
* FileHandle
* FindBin
* Font
    * AFM
* Getopt
    * Long
    * Std
* HTML
    * AsSubs
    * Element
    * Entities
    * Filter
    * Form
    * FormatPS
    * Formatter
    * FormatText
    * HeadParser
    * LinkExtor
    * Parse
    * Parser
    * TokeParser
    * TreeBuilder
* HTTP
    * Cookies
    * Daemon
    * Date
    * Headers
        * Util
    * Message
    * Negotiate
    * Request
        * Common
    * Response
    * Status
* I18N
    * Collate
* IO
    * Dir
    * File
    * Handle
    * Pipe
    * Poll
    * Seekable
    * Select
    * Socket
        * INET
        * UNIX
* IPC
    * Msg
    * Open2
    * Open3
    * Semaphore
    * SysV
* LWP
    * Debug
    * MediaTypes
    * MemberMixin
    * Protocol
    * RobotUA
    * Simple
    * UserAgent
* Math
    * BigFloat
    * BigInt
    * Complex
    * Trig
* MD5
* MIME
    * Base64
    * QuotedPrint
* NDBM_File
* Net
    * Cmd
    * Config
    * Domain
    * DummyInetd
    * FTP
    * hostent
    * libnetFAQ
    * netent
    * Netrc
    * NNTP
    * PH
    * Ping
    * POP3
    * protoent
    * servent
    * SMTP
    * SNPP
    * Time
* O
* ODBM_File
* Opcode
* Pod
    * Checker
    * Find
    * Html
    * InputObjects
    * Man
    * Parser
    * ParseUtils
    * Plainer
    * Select
    * Text
        * Color
        * Termcap
    * Usage
* POSIX
* PPM
    * SOAPClient
    * SOAPServer
* Safe
* SDBM_File
* Search
    * Dict
* SelectSaver
* SelfLoader
* SHA
* Shell
* SOAP
    * Defs
    * Envelope
    * EnvelopeMaker
    * GenericHashSerializer
    * GenericInputStream
    * GenericScalarSerializer
    * Lite
    * OutputStream
    * Packager
    * Parser
    * Transport
        * HTTP
            * Apache
            * CGI
            * Client
            * Server
        * LOCAL
        * MAILTO
        * POP3
        * TCP
    * TypeMapper
* Socket
* Symbol
* Sys
    * Hostname
    * Syslog
* Term
    * ANSIColor
    * Cap
    * Complete
    * ReadLine
* Test
    * Harness
* Text
    * Abbrev
    * ParseWords
    * Soundex
    * Tabs
    * Wrap
* Thread
    * Queue
    * Semaphore
    * Signal
    * Specific
* Tie
    * Array
    * Handle
    * Hash
    * RefHash
    * Scalar
    * SubstrHash
* Time
    * gmtime
    * Local
    * localtime
    * tm
* UDDI
    * Lite
* UNIVERSAL
* URI
    * data
    * Escape
    * file
    * Heuristic
    * ldap
    * URL
    * WithBase
* User
    * grent
    * pwent
* Win32
    * AuthenticateUser
    * ChangeNotify
    * Clipboard
    * Console
    * Event
    * EventLog
    * File
    * FileSecurity
    * Internet
    * IPC
    * Mutex
    * NetAdmin
    * NetResource
    * ODBC
    * OLE
        * Const
        * Enum
        * NEWS
        * NLS
        * TPJ
        * Variant
    * PerfLib
    * Pipe
    * Process
    * Registry
    * Semaphore
    * Service
    * Sound
    * TieRegistry
* Win32API
    * File
    * Net
    * Registry
* WWW
    * RobotRules
        * AnyDBM_File
* XML
    * Element
    * Parser
        * Expat
    * PPD
    * PPMConfig
    * ValidatingElement
* XSLoader

 Convert::ASN1 - ASN.1 Encode/Decode library


NAME

  Convert::ASN1 - ASN.1 Encode/Decode library


SUPPORTED PLATFORMS

  • Windows
This module is not included with the standard ActivePerl distribution. It is available as a separate download using PPM.

SYNOPSYS

  use Convert::ASN1;
  $asn = Convert::ASN1->new;
  $asn->prepare(q<
    [APPLICATION 7] SEQUENCE {
      int INTEGER,
      str OCTET STRING
    }
  >);
  $pdu = $asn->encode( int => 7, str => "string");
  $out = $asn->decode($pdu);
  print $out->{int}," ",$out->{str},"\n";
  use Convert::ASN1 qw(:io);
  $peer   = asn_recv($sock,$buffer,0);
  $nbytes = asn_read($fh, $buffer);
  $nbytes = asn_send($sock, $buffer, $peer);
  $nbytes = asn_send($sock, $buffer);
  $nbytes = asn_write($fh, $buffer);
  $buffer = asn_get($fh);
  $yes    = asn_ready($fh)


DESCRIPTION

Convert::ASN1 encodes and decodes ASN.1 data structures using BER/DER rules.


METHODS

new

Contructor, creates a new object.

error

Returns the last error.

configure ( OPTIONS )

Configure options to control how Convert::ASN1 will perform various tasks. Options are passed as name-value pairs.

encode
Reference to a hash which contains various encode options.

decode
Reference to a hash which contains various decode options.

encoding
One of 'ber', 'der', 'per'. Currently not used

Encode options

real
Which encoding to use for real's. One of 'binary', 'nr1', 'nr2', 'nr3'

timezone
By default UTCTime and GeneralizedTime will be encoded using the local time offset from UTC. This will over-ride that. It is an offset from UTC in seconds. Setting this to zero will make all Time values be passed as UTC. This option can be overriden by passing a reference to a list of two values as the time value. The list should contain the time value and the offset from UTC in seconds.

Decode options

timezone
By default UTCTime and GeneralizedTime will return just a time value. If this option is set to true then these type will return a reference to an array of two values. The first value is the time value. The second value is the offset from UTC in seconds.

prepare ( ASN )

Compile the given ASN.1 descripton. The syntax used is very close to ASN.1, but has a few differnces. If the ASN decribes only one macro then encode/decode can be called on this object. If ASN describes more than one ASN.1 macro then find must be called.

find ( MACRO )

Find a macro froma prepared ASN.1 description. Returns an object which can be used for encode/decode.

encode ( VARIABLES )

Encode a PDU. Top-level variable are passed as name-value pairs, or as a reference to a hash containing them. Returns the encoded PDU, or undef on error.

decode ( PDU )

Decode the PDU, returns a reference to a hash containg the values for the PDU. Returns undef if there was an error.


EXPORTS

As well as providing an object interface for encoding/decoding PDUs Convert::ASN1 also provides the follow functions.

IO Functions

asn_recv SOCK, BUFFER, FLAGS
Will read a single element from the socket SOCK into BUFFER. FLAGS may be MSG_PEEK as exported by Socket. Returns the address of the sender, or undef if there was an error. Some systems do not support the return of the peer address when the socket is a connected socket, in these cases the empty string will be returned. This is the same behaviour as the recv function in perl itself.

It is reccomended that if the socket is of type SOCK_DGRAM then recv be called directly instead of calling asn_recv.

asn_read FH, BUFFER, OFFSET
asn_read FH, BUFFER
Will read a single element from the filehandle FH into BUFFER. Returns the number of bytes read if a complete element was read, -1 if an incomplete element was read or undef if there was an error. If OFFSET is specified then it is assumed that BUFFER already contains an incomplete element and new data will be appended starting at OFFSET.

If FH is a socket the asn_recv is used to read the element, so the same restiction applies if FH is a socket of type SOCK_DGRAM.

asn_send SOCK, BUFFER, FLAGS, TO
asn_send SOCK, BUFFER, FLAGS
Identical to calling send, see the perlfunc manpage

asn_write FH, BUFFER
Identical to calling syswrite with 2 arguments, see the perlfunc manpage

asn_get FH
asn_get provides buffered IO. Because it needs a buffer FH must be a GLOB or a reference to a GLOB. asn_get will use two entries in the hash element of the GLOB to use as it's buffer
  asn_buffer - input buffer
  asn_need   - number of bytes needed for the next element, if known

Returns an element or undef if there was an error.

asn_ready FH
asn_ready works with asn_get. It will return true if asn_get has already read enough data into the buffer to return a complete element.

Encode/Decode Functions

asn_tag
asn_decode_tag
asn_encode_tag
asn_decode_length
asn_encode_length

Constants

ASN_BIT_STR
ASN_BOOLEAN
ASN_ENUMERATED
ASN_GENERAL_TIME
ASN_IA5_STR
ASN_INTEGER
ASN_NULL
ASN_OBJECT_ID
ASN_OCTET_STR
ASN_PRINT_STR
ASN_REAL
ASN_SEQUENCE
ASN_SET
ASN_UTC_TIME
ASN_APPLICATION
ASN_CONTEXT
ASN_PRIVATE
ASN_UNIVERSAL
ASN_PRIMITIVE
ASN_CONSTRUCTOR
ASN_LONG_LEN
ASN_EXTENSION_ID
ASN_BIT

Debug Functions

asn_dump
asn_hexdump


EXPORT TAGS

:all
All exported functions

:const
ASN_BOOLEAN, ASN_INTEGER, ASN_BIT_STR, ASN_OCTET_STR, ASN_NULL, ASN_OBJECT_ID, ASN_REAL, ASN_ENUMERATED, ASN_SEQUENCE, ASN_SET, ASN_PRINT_STR, ASN_IA5_STR, ASN_UTC_TIME, ASN_GENERAL_TIME, ASN_UNIVERSAL, ASN_APPLICATION, ASN_CONTEXT, ASN_PRIVATE, ASN_PRIMITIVE, ASN_CONSTRUCTOR, ASN_LONG_LEN, ASN_EXTENSION_ID, ASN_BIT

:debug
asn_dump, asn_dumphex

:io
asn_recv, asn_send, asn_read, asn_write, asn_get, asn_ready

:tag
asn_tag, asn_decode_tag, asn_encode_tag, asn_decode_length, asn_encode_length


MAPPING ASN.1 TO PERL

Every element in the ASN.1 definition has a name, in perl a hash is used with these names as an index and the element value as the hash value.

  # ASN.1
  int INTEGER,
  str OCTET STRING
  # Perl
  { int => 5, str => "text" }

In the case of a SEQUENCE, SET or CHOICE then the value in the namespace will be a hash reference which will be the namespce for the elements with that element.

  # ASN.1
  int INTEGER,
  seq SEQUENCE {
    str OCTET STRING,
    bool BOOLEAN
  }
  # Perl
  { int => 5, seq => { str => "text", bool => 1}}

If the element is a SEQUENCE OF, or SET OF, then the value in the namespace will be an array reference. The elements in the array will be of the type expected by the type following the OF. For example with ``SEQUENCE OF STRING'' the array would contain strings. With ``SEQUENCE OF SEQUENCE { ... }'' the array will contain hash references which will be used as namespaces

  # ASN.1
  int INTEGER,
  str SEQUENCE OF OCTET STRING
  # Perl
  { int => 5, str => [ "text1", "text2"]}
  # ASN.1
  int INTEGER,
  str SEQUENCE OF SEQUENCE {
    type OCTET STRING,
    value INTEGER
  }
  # Perl
  { int => 5, str => [
    { type => "abc", value => 4 },
    { type => "def", value => -1 },
  ]}

Exceptions

There are some exceptions where Convert::ASN1 does not require an element to be named. These are SEQUENCE {...}, SET {...} and CHOICE. In each case if the element is not given a name then the elements inside the {...} will share the same namespace as the elements outside of the {...}.


TODO

  • Decoding of a SET.

  • Indefinite length encoding

  • XS implementation.

  • More documentation.

  • More tests.


AUTHOR

Graham Barr <gbarr@pobox.xom>


COPYRIGHT

Copyright (c) 2000 Graham Barr <gbarr@pobox.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

 Convert::ASN1 - ASN.1 Encode/Decode library