vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #include <NULL.h> |
| 6 | #include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */ |
| 7 | |
| 8 | /* |
| 9 | * NULL basic type description. |
| 10 | */ |
| 11 | static ber_tlv_tag_t asn1_DEF_NULL_tags[] = { |
| 12 | (ASN_TAG_CLASS_UNIVERSAL | (5 << 2)) |
| 13 | }; |
| 14 | asn1_TYPE_descriptor_t asn1_DEF_NULL = { |
| 15 | "NULL", |
| 16 | asn_generic_no_constraint, |
| 17 | BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */ |
| 18 | NULL_encode_der, /* Special handling of DER encoding */ |
| 19 | NULL_print, |
| 20 | BOOLEAN_free, |
| 21 | 0, /* Use generic outmost tag fetcher */ |
| 22 | asn1_DEF_NULL_tags, |
| 23 | sizeof(asn1_DEF_NULL_tags)/sizeof(asn1_DEF_NULL_tags[0]), |
| 24 | 1, /* Single UNIVERSAL tag may be implicitly overriden */ |
vlm | b42843a | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 25 | 0, /* Always in primitive form */ |
| 26 | 0 /* No specifics */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | der_enc_rval_t |
| 30 | NULL_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, |
| 31 | int tag_mode, ber_tlv_tag_t tag, |
| 32 | asn_app_consume_bytes_f *cb, void *app_key) { |
| 33 | der_enc_rval_t erval; |
| 34 | |
| 35 | erval.encoded = der_write_tags(sd, 0, tag_mode, tag, cb, app_key); |
| 36 | if(erval.encoded == -1) { |
| 37 | erval.failed_type = sd; |
| 38 | erval.structure_ptr = ptr; |
| 39 | } |
| 40 | |
| 41 | return erval; |
| 42 | } |
| 43 | |
| 44 | int |
| 45 | NULL_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, |
| 46 | asn_app_consume_bytes_f *cb, void *app_key) { |
vlm | b42843a | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 47 | |
| 48 | (void)td; /* Unused argument */ |
| 49 | (void)ilevel; /* Unused argument */ |
| 50 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | if(sptr) { |
| 52 | return cb("<present>", 9, app_key); |
| 53 | } else { |
| 54 | return cb("<absent>", 8, app_key); |
| 55 | } |
| 56 | } |