6e91d9 | 2002-12-05 | H. William Welliver III | |
|
a580e1 | 2000-09-27 | Fredrik Hübinette (Hubbe) | | #pike __REAL_VERSION__
|
4e151b | 2008-05-02 | Martin Nilsson | | #pragma strict_types
|
3980c7 | 2003-01-26 | Martin Nilsson | | #define COMPATIBILITY
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
|
ffaf45 | 2004-04-14 | Martin Nilsson | | #if constant(Gmp) && constant(Gmp.mpz)
|
d9b402 | 1999-08-06 | Fredrik Hübinette (Hubbe) | |
|
3e031f | 1998-06-13 | Niels Möller | | #if 0
#define WERROR werror
#else
|
fa323d | 2004-02-29 | Martin Nilsson | | #define WERROR(x ...)
|
3e031f | 1998-06-13 | Niels Möller | | #endif
|
1ec5d6 | 1999-03-22 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
1ec5d6 | 1999-03-22 | Niels Möller | |
#define MAKE_COMBINED_TAG(cls, tag) (((tag) << 2) | (cls))
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
1ec5d6 | 1999-03-22 | Niels Möller | | int make_combined_tag(int cls, int tag)
{ return MAKE_COMBINED_TAG(cls, tag); }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
1ec5d6 | 1999-03-22 | Niels Möller | | int extract_tag(int i) { return i >> 2; }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
1ec5d6 | 1999-03-22 | Niels Möller | | int extract_cls(int i) { return i & 3; }
|
3980c7 | 2003-01-26 | Martin Nilsson | |
class Object
|
3e031f | 1998-06-13 | Niels Möller | | {
constant cls = 0;
constant tag = 0;
constant constructed = 0;
constant type_name = 0;
|
6e91d9 | 2002-12-05 | H. William Welliver III | | string der_encode();
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | int get_cls() { return cls; }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | int get_tag() { return tag; }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int get_combined_tag() {
return make_combined_tag(get_tag(), get_cls());
}
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | string der;
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object) decoder,
mapping(int:program(Object)) types);
|
f49ea8 | 2003-01-27 | Martin Nilsson | | this_program begin_decode_constructed(string raw);
this_program decode_constructed_element(int i, object e);
this_program end_decode_constructed(int length);
|
3e031f | 1998-06-13 | Niels Möller | |
|
c485aa | 2003-01-27 | Martin Nilsson | | mapping(int:program(Object)) element_types(int i,
mapping(int:program(Object)) types) {
|
7991f1 | 2008-01-05 | Henrik Grubbström (Grubba) | | return types; i;
|
c485aa | 2003-01-27 | Martin Nilsson | | }
|
7991f1 | 2008-01-05 | Henrik Grubbström (Grubba) | | this_program init(mixed ... args) { return this; args; }
|
3980c7 | 2003-01-26 | Martin Nilsson | |
string to_base_128(int n) {
if (!n)
return "\0";
array(int) digits = ({ });
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
while(n)
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | digits += ({ (n & 0x7f) | 0x80 });
n >>= 7;
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | | digits[0] &= 0x7f;
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | return sprintf("%@c", reverse(digits));
}
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string encode_tag() {
int tag = get_tag();
int cls = get_cls();
if (tag < 31)
return sprintf("%c", (cls << 6) | (constructed << 5) | tag);
return sprintf("%c%s", (cls << 6) | (constructed << 5) | 0x1f,
to_base_128(tag) );
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string encode_length(int|object len) {
if (len < 0x80)
return sprintf("%c", len);
string s = Gmp.mpz(len)->digits(256);
if (sizeof(s) >= 0x80)
error("Max length exceeded.\n" );
return sprintf("%c%s", sizeof(s) | 0x80, s);
}
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string build_der(string contents) {
string data = encode_tag() + encode_length(sizeof(contents)) + contents;
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("build_der: %O\n", data);
|
3980c7 | 2003-01-26 | Martin Nilsson | | return data;
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string record_der(string s) {
return (der = s);
}
|
0ecedd | 1999-03-23 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string record_der_contents(string s) {
record_der(build_der(s));
}
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
0a3877 | 2004-01-26 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
string get_der() {
return der || (record_der(der_encode()));
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | void create(mixed ...args) {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_object[%s]->create\n", type_name);
|
3980c7 | 2003-01-26 | Martin Nilsson | | if (sizeof(args))
init(@args);
}
|
3e031f | 1998-06-13 | Niels Möller | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Compound
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Object;
|
3e031f | 1998-06-13 | Niels Möller | |
constant constructed = 1;
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
032413 | 2004-01-27 | Martin Nilsson | | array(Object) elements = ({ });
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program init(array args) {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_compound[%s]->init(%O)\n", type_name, args);
|
3980c7 | 2003-01-26 | Martin Nilsson | | foreach(args, mixed o)
if (!objectp(o))
error( "Non-object argument!\n" );
|
009d77 | 2004-02-22 | Martin Nilsson | | elements = [array(Object)]args;
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_compound: %O\n", elements);
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program begin_decode_constructed(string raw) {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_compound[%s]->begin_decode_constructed\n", type_name);
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der_contents(raw);
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program decode_constructed_element(int i, object e) {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_compound[%s]->decode_constructed_element(%O)\n",
type_name, e);
|
3980c7 | 2003-01-26 | Martin Nilsson | | if (i != sizeof(elements))
error("Unexpected index!\n");
elements += ({ e });
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program end_decode_constructed(int length) {
if (length != sizeof(elements))
error("Invalid length!\n");
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
36261f | 2013-03-01 | Chris Angelico | | protected string _sprintf(int t,mapping(string:int)|void params) {
if (params) ++params->indent; else params=([]);
return t=='O' && sprintf("%O(%s %*O)", this_program, type_name, params, elements);
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | #ifdef COMPATIBILITY
string debug_string() {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_compound[%s]->debug_string(), elements = %O\n",
type_name, elements);
|
3980c7 | 2003-01-26 | Martin Nilsson | | return _sprintf('O');
}
#endif
|
3e031f | 1998-06-13 | Niels Möller | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class String
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Object;
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | string value;
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program init(string s) {
value = s;
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
return build_der(value);
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der_contents(contents);
value = contents;
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
9eaf1d | 2008-06-28 | Martin Nilsson | | protected string _sprintf(int t) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | return t=='O' && sprintf("%O(%s, %O)", this_program, type_name, value);
}
#ifdef COMPATIBILITY
string debug_string() {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_string[%s]->debug_string(), value = %O\n", type_name, value);
|
3980c7 | 2003-01-26 | Martin Nilsson | | return _sprintf('O');
}
#endif
|
3e031f | 1998-06-13 | Niels Möller | | }
|
47b591 | 1999-02-19 | Niels Möller | |
|
ffbc62 | 2003-01-28 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Boolean
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Object;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 1;
constant type_name = "BOOLEAN";
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | int value;
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program init(int x) {
value = x;
return this;
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | string der_encode() {
return build_der(value ? "\377" : "\0");
}
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der_contents(contents);
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | value = (contents != "\0");
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
9eaf1d | 2008-06-28 | Martin Nilsson | | protected string _sprintf(int t) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | return t=='O' && sprintf("%O(%s)", this_program, (value?"TRUE":"FALSE"));
}
#ifdef COMPATIBILITY
string debug_string() {
return value ? "TRUE" : "FALSE";
}
#endif
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Integer
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Object;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 2;
constant type_name = "INTEGER";
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
Gmp.mpz value;
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_object init(int|object n) {
value = Gmp.mpz(n);
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("i = %s\n", value->digits());
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
string s;
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | if (value < 0)
|
3e031f | 1998-06-13 | Niels Möller | | {
|
009d77 | 2004-02-22 | Martin Nilsson | | Gmp.mpz n = [object(Gmp.mpz)](value +
pow(256, ([object(Gmp.mpz)](- value))->
size(256)));
|
3980c7 | 2003-01-26 | Martin Nilsson | | s = n->digits(256);
if (!(s[0] & 0x80))
s = "\377" + s;
} else {
s = value->digits(256);
if (s[0] & 0x80)
s = "\0" + s;
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | | return build_der(s);
}
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_object decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der_contents(contents);
value = Gmp.mpz(contents, 256);
if (contents[0] & 0x80)
value -= pow(256, sizeof(contents));
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
9eaf1d | 2008-06-28 | Martin Nilsson | | protected string _sprintf(int t) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | return t=='O' && sprintf("%O(%d %s)", this_program,
value->size(), value->digits());
}
#ifdef COMPATIBILITY
string debug_string() {
return sprintf("INTEGER (%d) %s", value->size(), value->digits());
}
#endif
|
3e031f | 1998-06-13 | Niels Möller | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Enumerated
|
47b591 | 1999-02-19 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Integer;
|
47b591 | 1999-02-19 | Niels Möller | | constant tag = 10;
constant type_name ="ENUMERATED";
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class BitString
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Object;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 3;
constant type_name = "BIT STRING";
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | string value;
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3e031f | 1998-06-13 | Niels Möller | | int unused = 0;
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program init(string s) {
value = s;
return this;
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
return build_der(sprintf("%c%s", unused, value));
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
78e418 | 2004-02-22 | Martin Nilsson | |
this_program set_from_ascii(string s) {
array v = array_sscanf(s, "%8b"*(sizeof(s)/8)+"%b");
v[-1] = v[-1]<<((-sizeof(s))%8);
value = (string)v;
set_length(sizeof(s));
return this;
}
|
3980c7 | 2003-01-26 | Martin Nilsson | | int set_length(int len) {
if (len)
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | value = value[..(len + 7)/8];
unused = (- len) % 8;
|
8a531a | 2006-11-04 | Martin Nilsson | | value = sprintf("%s%c", value[..<1], value[-1]
|
78e418 | 2004-02-22 | Martin Nilsson | | & ({ 0xff, 0xfe, 0xfc, 0xf8,
0xf0, 0xe0, 0xc0, 0x80 })[unused]);
|
3980c7 | 2003-01-26 | Martin Nilsson | | } else {
unused = 0;
value = "";
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der_contents(contents);
if (!sizeof(contents))
return 0;
unused = contents[0];
if (unused >= 8)
return 0;
value = contents[1..];
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
9eaf1d | 2008-06-28 | Martin Nilsson | | protected string _sprintf(int t) {
|
78e418 | 2004-02-22 | Martin Nilsson | | int size = sizeof(value)*8-unused;
return t=='O' && sprintf("%O(%d %0"+size+"s)", this_program, size,
|
009d77 | 2004-02-22 | Martin Nilsson | | ([object(Gmp.mpz)](Gmp.mpz(value, 256) >> unused))
->digits(2));
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
#ifdef COMPATIBILITY
string debug_string() {
return sprintf("BIT STRING (%d) %s",
sizeof(value) * 8 - unused,
|
009d77 | 2004-02-22 | Martin Nilsson | | ([object(Gmp.mpz)](Gmp.mpz(value, 256) >> unused))
->digits(2));
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
#endif
|
3e031f | 1998-06-13 | Niels Möller | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class OctetString
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit String;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 4;
constant type_name = "OCTET STRING";
}
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Null
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Object;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 5;
constant type_name = "NULL";
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | string der_encode() { return build_der(""); }
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der_contents(contents);
|
563bd7 | 2004-01-11 | Martin Nilsson | | return !sizeof(contents) && this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | #ifdef COMPATIBILITY
|
3e031f | 1998-06-13 | Niels Möller | | string debug_string() { return "NULL"; }
|
3980c7 | 2003-01-26 | Martin Nilsson | | #endif
|
3e031f | 1998-06-13 | Niels Möller | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Identifier
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Object;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 6;
constant type_name = "OBJECT IDENTIFIER";
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
3e031f | 1998-06-13 | Niels Möller | | array(int) id;
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program init(int ... args) {
if ( (sizeof(args) < 2)
|| (args[0] > 2)
|| (args[1] >= ( (args[0] < 2) ? 40 : 176) ))
error( "Invalid object identifier.\n" );
id = args;
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | | mixed _encode() { return id; }
|
3980c7 | 2003-01-26 | Martin Nilsson | | void _decode(array(int) data) { id=data; }
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | |
|
86e5af | 2004-02-22 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program append(int ... args) {
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this_program(@id, @args);
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
|
86e5af | 2004-02-22 | Martin Nilsson | | return build_der(sprintf("%s%@s", to_base_128(40 * id[0] + id[1]),
|
3980c7 | 2003-01-26 | Martin Nilsson | | map(id[2..], to_base_128)));
}
|
3e031f | 1998-06-13 | Niels Möller | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der_contents(contents);
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | if (contents[0] < 120)
id = ({ contents[0] / 40, contents[0] % 40 });
else
id = ({ 2, contents[0] - 80 });
int index = 1;
while(index < sizeof(contents))
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | int element = 0;
do {
element = element << 7 | (contents[index] & 0x7f);
} while(contents[index++] & 0x80);
id += ({ element });
|
3e031f | 1998-06-13 | Niels Möller | | }
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
9eaf1d | 2008-06-28 | Martin Nilsson | | protected string _sprintf(int t) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | return t=='O' && sprintf("%O(%s)", this_program, (array(string))id*".");
}
#ifdef COMPATIBILITY
string debug_string() {
return "IDENTIFIER " + (array(string)) id * ".";
}
#endif
|
0a3877 | 2004-01-26 | H. William Welliver III | | int __hash()
{
return hash(get_der());
}
|
3980c7 | 2003-01-26 | Martin Nilsson | | int `==(mixed other) {
return (objectp(other) &&
|
563bd7 | 2004-01-11 | Martin Nilsson | | (this_program == object_program(other)) &&
|
009d77 | 2004-02-22 | Martin Nilsson | | equal(id, ([object(Identifier)]other)->id));
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int(1..1) asn1_utf8_valid (string s)
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
7991f1 | 2008-01-05 | Henrik Grubbström (Grubba) | | return 1; s;
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class UTF8String
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit String;
|
a6914b | 1999-06-07 | Martin Stjernholm | | constant tag = 12;
constant type_name = "UTF8String";
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
return build_der(string_to_utf8(value));
}
|
a6914b | 1999-06-07 | Martin Stjernholm | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive(string(0..255) contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | record_der(contents);
if (catch {
value = utf8_to_string(contents);
})
return 0;
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
}
|
a6914b | 1999-06-07 | Martin Stjernholm | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Sequence
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Compound;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 16;
constant type_name = "SEQUENCE";
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("ASN1.Sequence: elements = '%O\n", elements);
|
3980c7 | 2003-01-26 | Martin Nilsson | | array(string) a = elements->get_der();
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("ASN1.Sequence: der_encode(elements) = '%O\n", a);
|
3980c7 | 2003-01-26 | Martin Nilsson | | return build_der(`+("", @ a));
}
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | |
this_program decode_primitive(string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object) decoder,
mapping(int:program(Object)) types) {
record_der(contents);
elements = ({});
ADT.struct struct = ADT.struct(contents);
while (!struct->is_empty()) {
elements += ({ decoder(struct, types) });
}
return this;
}
|
3e031f | 1998-06-13 | Niels Möller | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class Set
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit Compound;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 17;
constant type_name = "SET";
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | int(-1..1) compare_octet_strings(string r, string s) {
for(int i = 0;; i++) {
if (i == sizeof(r))
return (i = sizeof(s)) ? 0 : 1;
if (i == sizeof(s))
return -1;
if (r[i] < s[i])
return 1;
else if (r[i] > s[i])
return -1;
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_set->der: elements = '%O\n", elements);
|
3980c7 | 2003-01-26 | Martin Nilsson | | array(string) a = elements->get_der();
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_set->der: der_encode(elements) = '%O\n", a);
|
009d77 | 2004-02-22 | Martin Nilsson | | return build_der(`+("", @[array(string)]
Array.sort_array(a, compare_octet_strings)));
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | | Regexp asn1_printable_invalid_chars = Regexp("([^-A-Za-z0-9 '()+,./:=?])");
|
a6914b | 1999-06-07 | Martin Stjernholm | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int(0..1) asn1_printable_valid (string s) {
if (global.String.width(s)!=8) return 0;
return !asn1_printable_invalid_chars->match(s);
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class PrintableString
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit String;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 19;
constant type_name = "PrintableString";
}
|
3980c7 | 2003-01-26 | Martin Nilsson | | Regexp asn1_teletex_invalid_chars = Regexp ("([\\\\{}\240®©¬¦\255Ð])");
|
a6914b | 1999-06-07 | Martin Stjernholm | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int(0..1) asn1_teletex_valid (string s)
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | if (global.String.width(s)!=8)
|
a6914b | 1999-06-07 | Martin Stjernholm | |
return 0;
return !asn1_teletex_invalid_chars->match (s);
}
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | |
|
3f5bd4 | 2008-04-22 | Henrik Grubbström (Grubba) | |
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | |
|
0b8d2f | 2013-06-17 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class TeletexString
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit String;
|
a6914b | 1999-06-07 | Martin Stjernholm | | constant tag = 20;
constant type_name = "TeletexString";
#define ENC_ERR(char) char
#define DEC_ERR(str) str
#define DEC_COMB_MARK "\300"
#define GR(char) "\301" char /* Combining grave accent */
#define AC(char) "\302" char /* Combining acute accent */
#define CI(char) "\303" char /* Combining circumflex accent */
#define TI(char) "\304" char /* Combining tilde */
#define MA(char) "\305" char /* Combining macron */
#define BR(char) "\306" char /* Combining breve */
#define DA(char) "\307" char /* Combining dot above */
#define DI(char) "\310" char /* Combining diaeresis */
#define RA(char) "\312" char /* Combining ring above */
#define CE(char) "\313" char /* Combining cedilla */
#define UN(char) "\314" char /* Combining underscore (note 6) */
#define DO(char) "\315" char /* Combining double acute accent */
#define OG(char) "\316" char /* Combining ogonek */
#define CA(char) "\317" char /* Combining caron */
constant encode_from = ({
"¤",
"\\", "{", "}",
"\240",
"×",
"÷",
"¹",
"®",
"©",
"¬",
"¦",
"Æ",
"ª",
"Ø",
"º",
"Þ",
"æ",
"ð",
"ø",
"ß",
"þ",
"\255",
"Ð",
"^", "`", "~",
"´", "¨", "¯", "¸",
"À", "Á", "Â", "Ã", "Ä", "Å",
"à", "á", "â", "ã", "ä", "å",
"Ç",
"ç",
"È", "É", "Ê", "Ë",
"è", "é", "ê", "ë",
"Ì", "Í", "Î", "Ï",
"ì", "í", "î", "ï",
"Ñ",
"ñ",
"Ò", "Ó", "Ô", "Õ", "Ö",
"ò", "ó", "ô", "õ", "ö",
"Ù", "Ú", "Û", "Ü",
"ù", "ú", "û", "ü",
"Ý",
"ý",
});
constant encode_to = ({
"\250",
ENC_ERR("\\"), ENC_ERR("{"), ENC_ERR("}"),
ENC_ERR("\240"),
"\264",
"\270",
"\321",
ENC_ERR("®"),
ENC_ERR("©"),
ENC_ERR("¬"),
ENC_ERR("¦"),
"\341",
"\343",
"\351",
"\353",
"\354",
"\361",
"\363",
"\371",
"\373",
"\374",
ENC_ERR("\255"),
ENC_ERR("Ð"),
CI(" "), GR(" "), TI(" "),
AC(" "), DI(" "), MA(" "), CE(" "),
GR("A"), AC("A"), CI("A"), TI("A"), DI("A"), RA("A"),
GR("a"), AC("a"), CI("a"), TI("a"), DI("a"), RA("a"),
CE("C"),
CE("c"),
GR("E"), AC("E"), CI("E"), DI("E"),
GR("e"), AC("e"), CI("e"), DI("e"),
GR("I"), AC("I"), CI("I"), DI("I"),
GR("i"), AC("i"), CI("i"), DI("i"),
TI("N"),
TI("n"),
GR("O"), AC("O"), CI("O"), TI("O"), DI("O"),
GR("o"), AC("o"), CI("o"), TI("o"), DI("o"),
GR("U"), AC("U"), CI("U"), DI("U"),
GR("u"), AC("u"), CI("u"), DI("u"),
GR("Y"),
GR("y"),
});
constant decode_from = ({
"\244", "\246", "\250",
"\251",
"\252",
"\254",
"\255",
"\256",
"\257",
"\264",
"\270",
"\271",
"\272",
"\300",
GR(""),
AC(""),
CI(""),
TI(""),
MA(""),
BR(""),
DA(""),
DI(""),
"\311",
RA(""),
CE(""),
UN(""),
DO(""),
OG(""),
CA(""),
"\320",
"\321",
"\322",
"\323",
"\324",
"\325",
"\326",
"\327",
"\330", "\331", "\332", "\333",
"\334",
"\335",
"\336",
"\337",
"\340",
"\341",
"\342",
"\343",
"\344",
"\345",
"\346",
"\347",
"\350",
"\351",
"\352",
"\353",
"\354",
"\355",
"\356",
"\357",
"\360",
"\361",
"\362",
"\363",
"\364",
"\365",
"\366",
"\367",
"\370",
"\371",
"\372",
"\373",
"\374",
"\375",
"\376",
"\377",
});
constant decode_to = ({
"$", "#", "\244",
DEC_ERR("\251"),
DEC_ERR("\252"),
DEC_ERR("\254"),
DEC_ERR("\255"),
DEC_ERR("\256"),
DEC_ERR("\257"),
"×",
"÷",
DEC_ERR("\271"),
DEC_ERR("\272"),
DEC_ERR("\300"),
DEC_COMB_MARK GR(""),
DEC_COMB_MARK AC(""),
DEC_COMB_MARK CI(""),
DEC_COMB_MARK TI(""),
DEC_COMB_MARK MA(""),
DEC_COMB_MARK BR(""),
DEC_COMB_MARK DA(""),
DEC_COMB_MARK DI(""),
DEC_ERR("\311"),
DEC_COMB_MARK RA(""),
DEC_COMB_MARK CE(""),
DEC_COMB_MARK UN(""),
DEC_COMB_MARK DO(""),
DEC_COMB_MARK OG(""),
DEC_COMB_MARK CA(""),
DEC_ERR("\320"),
"¹",
"®",
"©",
DEC_ERR("\324"),
DEC_ERR("\325"),
"¬",
"¦",
DEC_ERR("\330"), DEC_ERR("\331"), DEC_ERR("\332"), DEC_ERR("\333"),
DEC_ERR("\334"),
DEC_ERR("\335"),
DEC_ERR("\336"),
DEC_ERR("\337"),
DEC_ERR("\340"),
"Æ",
DEC_ERR("\342"),
"ª",
DEC_ERR("\344"),
DEC_ERR("\345"),
DEC_ERR("\346"),
DEC_ERR("\347"),
DEC_ERR("\350"),
"Ø",
DEC_ERR("\352"),
"º",
"Þ",
DEC_ERR("\355"),
DEC_ERR("\356"),
DEC_ERR("\357"),
DEC_ERR("\360"),
"æ",
DEC_ERR("\362"),
"ð",
DEC_ERR("\364"),
DEC_ERR("\365"),
DEC_ERR("\366"),
DEC_ERR("\367"),
DEC_ERR("\370"),
"ø",
DEC_ERR("\372"),
"ß",
"þ",
DEC_ERR("\375"),
DEC_ERR("\376"),
"\255",
});
constant decode_comb = ([
GR(" "): "`",
AC(" "): "´",
CI(" "): "^",
TI(" "): "~",
DI(" "): "¨",
MA(" "): "¯",
CE(" "): "¸",
GR("A"): "À", AC("A"): "Á", CI("A"): "Â", TI("A"): "Ã", DI("A"): "Ä", RA("A"): "Å",
GR("a"): "à", AC("a"): "á", CI("a"): "â", TI("a"): "ã", DI("a"): "ä", RA("a"): "å",
CE("C"): "Ç",
CE("c"): "ç",
GR("E"): "È", AC("E"): "É", CI("E"): "Ê", DI("E"): "Ë",
GR("e"): "è", AC("e"): "é", CI("e"): "ê", DI("e"): "ë",
GR("I"): "Ì", AC("I"): "Í", CI("I"): "Î", DI("I"): "Ï",
GR("i"): "ì", AC("i"): "í", CI("i"): "î", DI("i"): "ï",
TI("N"): "Ñ",
TI("n"): "ñ",
GR("O"): "Ò", AC("O"): "Ó", CI("O"): "Ô", TI("O"): "Õ", DI("O"): "Ö",
GR("o"): "ò", AC("o"): "ó", CI("o"): "ô", TI("o"): "õ", DI("o"): "ö",
GR("U"): "Ù", AC("U"): "Ú", CI("U"): "Û", DI("U"): "Ü",
GR("u"): "ù", AC("u"): "ú", CI("u"): "û", DI("u"): "ü",
GR("Y"): "Ý",
GR("y"): "ý",
]);
#undef GR
#undef AC
#undef CI
#undef TI
#undef MA
#undef BR
#undef DA
#undef DI
#undef RA
#undef CE
#undef UN
#undef DO
#undef OG
#undef CA
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
|
28c6d5 | 2004-02-23 | Martin Nilsson | | return build_der(replace(value, [array(string)]encode_from,
[array(string)]encode_to));
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive (string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
a6914b | 1999-06-07 | Martin Stjernholm | | record_der (contents);
array(string) parts =
|
28c6d5 | 2004-02-23 | Martin Nilsson | | replace (contents, [array(string)]decode_from,
[array(string)]decode_to) / DEC_COMB_MARK;
|
a6914b | 1999-06-07 | Martin Stjernholm | | value = parts[0];
foreach (parts[1..], string part)
value += (decode_comb[part[..1]] || DEC_ERR(part[..1])) + part[2..];
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
#undef ENC_ERR
#undef DEC_ERR
#undef DEC_COMB_MARK
}
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int(0..1) asn1_broken_teletex_valid (string s)
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | return global.String.width(s)==8;
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class BrokenTeletexString
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit String;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 20;
|
a6914b | 1999-06-07 | Martin Stjernholm | | constant type_name = "TeletexString";
}
|
8b72ec | 2005-01-21 | Martin Stjernholm | | Regexp asn1_IA5_invalid_chars = Regexp ("([\200-\377])");
|
a6914b | 1999-06-07 | Martin Stjernholm | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int(0..1) asn1_IA5_valid (string s)
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | if (global.String.width(s)!=8) return 0;
|
a6914b | 1999-06-07 | Martin Stjernholm | | return !asn1_printable_invalid_chars->match (s);
|
3e031f | 1998-06-13 | Niels Möller | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class IA5String
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit String;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 22;
constant type_name = "IA5STRING";
}
|
53df71 | 2003-01-26 | Martin Nilsson | |
|
ffbc62 | 2003-01-28 | Martin Nilsson | |
class VisibleString {
inherit String;
constant tag = 26;
constant type_name = "VisibleString";
}
|
53df71 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class UTC
|
3e031f | 1998-06-13 | Niels Möller | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit String;
|
3e031f | 1998-06-13 | Niels Möller | | constant tag = 23;
constant type_name = "UTCTime";
}
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int(0..0) asn1_universal_valid (string s)
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
7991f1 | 2008-01-05 | Henrik Grubbström (Grubba) | | return 0; s;
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class UniversalString
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit OctetString;
|
a6914b | 1999-06-07 | Martin Stjernholm | | constant tag = 28;
constant type_name = "UniversalString";
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
error( "Encoding not implemented\n" );
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive (string contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
7991f1 | 2008-01-05 | Henrik Grubbström (Grubba) | | error( "Decoding not implemented\n" ); contents;
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
}
|
3980c7 | 2003-01-26 | Martin Nilsson | |
int(0..1) asn1_bmp_valid (string s)
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | return global.String.width(s)<32;
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class BMPString
|
a6914b | 1999-06-07 | Martin Stjernholm | | {
|
3980c7 | 2003-01-26 | Martin Nilsson | | inherit OctetString;
|
a6914b | 1999-06-07 | Martin Stjernholm | | constant tag = 30;
constant type_name = "BMPString";
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
|
a6914b | 1999-06-07 | Martin Stjernholm | | return build_der (string_to_unicode (value));
}
|
12e490 | 2008-04-22 | Henrik Grubbström (Grubba) | | this_program decode_primitive (string(0..255) contents,
function(ADT.struct,
mapping(int:program(Object)):
Object)|void decoder,
mapping(int:program(Object))|void types) {
|
a6914b | 1999-06-07 | Martin Stjernholm | | record_der (contents);
value = unicode_to_string (contents);
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
a6914b | 1999-06-07 | Martin Stjernholm | | }
}
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
6e91d9 | 2002-12-05 | H. William Welliver III | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class MetaExplicit
|
3e031f | 1998-06-13 | Niels Möller | | {
int real_tag;
|
1ec5d6 | 1999-03-22 | Niels Möller | | int real_cls;
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
c485aa | 2003-01-27 | Martin Nilsson | | mapping(int:program(Object)) valid_types;
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | class `() {
inherit Compound;
constant type_name = "EXPLICIT";
constant constructed = 1;
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | int get_tag() { return real_tag; }
int get_cls() { return real_cls; }
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | Object contents;
|
3e031f | 1998-06-13 | Niels Möller | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | this_program init(Object o) {
contents = o;
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
3980c7 | 2003-01-26 | Martin Nilsson | | string der_encode() {
|
fa323d | 2004-02-29 | Martin Nilsson | | WERROR("asn1_explicit->der: contents = '%O\n", contents);
|
3980c7 | 2003-01-26 | Martin Nilsson | | return build_der(contents->get_der());
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | |
this_program decode_constructed_element(int i, Object e) {
if (i)
error("Unexpected index!\n");
contents = e;
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
this_program end_decode_constructed(int length) {
if (length != 1)
error("length != 1!\n");
|
563bd7 | 2004-01-11 | Martin Nilsson | | return this;
|
3e031f | 1998-06-13 | Niels Möller | | }
|
3980c7 | 2003-01-26 | Martin Nilsson | |
|
c485aa | 2003-01-27 | Martin Nilsson | | mapping(int:program(Object)) element_types(int i,
mapping(int:program(Object)) types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | if (i)
error("Unexpected index!\n");
return valid_types || types;
}
|
9eaf1d | 2008-06-28 | Martin Nilsson | | protected string _sprintf(int t) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | return t=='O' && sprintf("%O(%s %d %O)", this_program, type_name,
real_tag, contents);
}
#ifdef COMPATIBILITY
string debug_string() {
|
009d77 | 2004-02-22 | Martin Nilsson | | return type_name + "[" + (int) real_tag + "]";
|
3980c7 | 2003-01-26 | Martin Nilsson | | }
#endif
}
|
17e742 | 2003-01-26 | Martin Nilsson | |
|
c485aa | 2003-01-27 | Martin Nilsson | | void create(int cls, int tag, mapping(int:program(Object))|void types) {
|
3980c7 | 2003-01-26 | Martin Nilsson | | real_cls = cls;
real_tag = tag;
valid_types = types;
}
|
3e031f | 1998-06-13 | Niels Möller | | }
|
d9b402 | 1999-08-06 | Fredrik Hübinette (Hubbe) | |
|
3980c7 | 2003-01-26 | Martin Nilsson | |
#ifdef COMPATIBILITY
constant meta_explicit = MetaExplicit;
constant asn1_object = Object;
constant asn1_compound = Compound;
constant asn1_string = String;
constant asn1_boolean = Boolean;
constant asn1_integer = Integer;
constant asn1_enumerated = Enumerated;
constant asn1_bit_string = BitString;
constant asn1_octet_string = OctetString;
constant asn1_null = Null;
constant asn1_identifier = Identifier;
constant asn1_utf8_string = UTF8String;
constant asn1_sequence = Sequence;
constant asn1_set = Set;
constant asn1_printable_string = PrintableString;
constant asn1_teletex_string = TeletexString;
constant asn1_broken_teletex_string = BrokenTeletexString;
constant asn1_IA5_string = IA5String;
|
53df71 | 2003-01-26 | Martin Nilsson | | constant asn1_utc = UTC;
|
3980c7 | 2003-01-26 | Martin Nilsson | | constant asn1_universal_string = UniversalString;
constant asn1_bmp_string = BMPString;
#endif
|
ffaf45 | 2004-04-14 | Martin Nilsson | | #else
constant this_program_does_not_exist=1;
|
4c2442 | 1999-08-08 | Henrik Grubbström (Grubba) | | #endif /* Gmp.mpz */
|