Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #4019

Parse ASN.1 DER format

Path csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From news@zzo38computer.org.invalid
Newsgroups comp.lang.postscript
Subject Parse ASN.1 DER format
Date Wed, 22 Oct 2025 14:38:43 -0700
Organization A noiseless patient Spider
Lines 42
Message-ID <1761168222.bystand@zzo38computer.org> (permalink)
MIME-Version 1.0
Injection-Date Wed, 22 Oct 2025 21:39:18 +0000 (UTC)
Injection-Info dont-email.me; posting-host="c85a56b2d1cdee3b342590a61db3cd22"; logging-data="983499"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+v13wXCEqPMElqa46vObmd"
User-Agent bystand/1.3.0pre1
Cancel-Lock sha1:VOinU4nIB71pu5DTbivegiP7m2Y=
Xref csiph.com comp.lang.postscript:4019

Show key headers only | View raw


I wrote a PostScript code to parse ASN.1 DER format. (This file is
public domain.)

Currently it only implements decoding and not encoding. Also, it only
decodes the framing and does not decode values.

/ASN1class [/Universal /Application /Context /Private] def

/ASN1parse {
  dup read {
    << >> begin
    /Tag exch def
    /File exch def
    /Constructed Tag -5 bitshift 0 ne def
    /Class //ASN1class Tag -6 bitshift get def
    /Tag Tag 16#1F and dup 16#1F eq {
      pop 0 {File read {
        exch 7 bitshift 1 index 16#7F and or
        exch 16#80 lt {exit} if
      } {exit} ifelse} loop
    } if def
    /Length File read pop def
    Length 16#80 ge {
      /Length 0 Length 16#7F and {
        8 bitshift File read {or} if
      } repeat def
    } if
    /Data Constructed {
      /File File Length () /SubFileDecode filter def
      [{File ASN1parse not {exit} if} loop]
    } {
      Length 0 eq {()} {File Length string readstring pop} ifelse
    } ifelse def
    {File Constructed Length} {currentdict exch undef} forall
    currentdict end //true
  } {
    pop //false
  } ifelse
} bind def

-- 
Don't laugh at the moon when it is day time in France.

Back to comp.lang.postscript | Previous | Next | Find similar | Unroll thread


Thread

Parse ASN.1 DER format news@zzo38computer.org.invalid - 2025-10-22 14:38 -0700

csiph-web