| Line | Source | Count |
| 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 | #include <openssl/asn1.h> | - |
| 56 | #include <openssl/asn1t.h> | - |
| 57 | #include <openssl/bio.h> | - |
| 58 | #include <openssl/err.h> | - |
| 59 | | - |
| 60 | #include <stdio.h> | - |
| 61 | | - |
| 62 | | - |
| 63 | | - |
| 64 | | - |
| 65 | | - |
| 66 | | - |
| 67 | | - |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | typedef struct ndef_aux_st { | - |
| 82 | | - |
| 83 | ASN1_VALUE *val; | - |
| 84 | const ASN1_ITEM *it; | - |
| 85 | | - |
| 86 | BIO *ndef_bio; | - |
| 87 | | - |
| 88 | BIO *out; | - |
| 89 | | - |
| 90 | unsigned char **boundary; | - |
| 91 | | - |
| 92 | unsigned char *derbuf; | - |
| 93 | } NDEF_SUPPORT; | - |
| 94 | | - |
| 95 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg); | - |
| 96 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); | - |
| 97 | static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg); | - |
| 98 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); | - |
| 99 | | - |
| 100 | BIO * | - |
| 101 | BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) | - |
| 102 | { | - |
| 103 | NDEF_SUPPORT *ndef_aux = NULL; | - |
| 104 | BIO *asn_bio = NULL; | - |
| 105 | const ASN1_AUX *aux = it->funcs; | - |
| 106 | ASN1_STREAM_ARG sarg; | - |
| 107 | | - |
| 108 | if (!aux || !aux->asn1_cb) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 109 | ASN1error(ASN1_R_STREAMING_NOT_SUPPORTED); | - |
| 110 | return NULL; never executed: return ((void *)0) ; | 0 |
| 111 | } | - |
| 112 | ndef_aux = malloc(sizeof(NDEF_SUPPORT)); | - |
| 113 | asn_bio = BIO_new(BIO_f_asn1()); | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | out = BIO_push(asn_bio, out); | - |
| 118 | | - |
| 119 | if (!ndef_aux || !asn_bio || !out)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 120 | goto err; never executed: goto err; | 0 |
| 121 | | - |
| 122 | BIO_asn1_set_prefix(asn_bio, ndef_prefix, ndef_prefix_free); | - |
| 123 | BIO_asn1_set_suffix(asn_bio, ndef_suffix, ndef_suffix_free); | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | | - |
| 129 | sarg.out = out; | - |
| 130 | sarg.ndef_bio = NULL; | - |
| 131 | sarg.boundary = NULL; | - |
| 132 | | - |
| 133 | if (aux->asn1_cb(ASN1_OP_STREAM_PRE, &val, it, &sarg) <= 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 134 | goto err; never executed: goto err; | 0 |
| 135 | | - |
| 136 | ndef_aux->val = val; | - |
| 137 | ndef_aux->it = it; | - |
| 138 | ndef_aux->ndef_bio = sarg.ndef_bio; | - |
| 139 | ndef_aux->boundary = sarg.boundary; | - |
| 140 | ndef_aux->out = out; | - |
| 141 | | - |
| 142 | BIO_ctrl(asn_bio, BIO_C_SET_EX_ARG, 0, ndef_aux); | - |
| 143 | | - |
| 144 | return sarg.ndef_bio; never executed: return sarg.ndef_bio; | 0 |
| 145 | | - |
| 146 | err: | - |
| 147 | BIO_free(asn_bio); | - |
| 148 | free(ndef_aux); | - |
| 149 | return NULL; never executed: return ((void *)0) ; | 0 |
| 150 | } | - |
| 151 | | - |
| 152 | static int | - |
| 153 | ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | - |
| 154 | { | - |
| 155 | NDEF_SUPPORT *ndef_aux; | - |
| 156 | unsigned char *p; | - |
| 157 | int derlen; | - |
| 158 | | - |
| 159 | if (!parg)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 160 | return 0; never executed: return 0; | 0 |
| 161 | | - |
| 162 | ndef_aux = *(NDEF_SUPPORT **)parg; | - |
| 163 | | - |
| 164 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); | - |
| 165 | p = malloc(derlen); | - |
| 166 | ndef_aux->derbuf = p; | - |
| 167 | *pbuf = p; | - |
| 168 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it); | - |
| 169 | | - |
| 170 | if (!*ndef_aux->boundary)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 171 | return 0; never executed: return 0; | 0 |
| 172 | | - |
| 173 | *plen = *ndef_aux->boundary - *pbuf; | - |
| 174 | | - |
| 175 | return 1; never executed: return 1; | 0 |
| 176 | } | - |
| 177 | | - |
| 178 | static int | - |
| 179 | ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | - |
| 180 | { | - |
| 181 | NDEF_SUPPORT *ndef_aux; | - |
| 182 | | - |
| 183 | if (!parg)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 184 | return 0; never executed: return 0; | 0 |
| 185 | | - |
| 186 | ndef_aux = *(NDEF_SUPPORT **)parg; | - |
| 187 | | - |
| 188 | free(ndef_aux->derbuf); | - |
| 189 | | - |
| 190 | ndef_aux->derbuf = NULL; | - |
| 191 | *pbuf = NULL; | - |
| 192 | *plen = 0; | - |
| 193 | return 1; never executed: return 1; | 0 |
| 194 | } | - |
| 195 | | - |
| 196 | static int | - |
| 197 | ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | - |
| 198 | { | - |
| 199 | NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg; | - |
| 200 | if (!ndef_prefix_free(b, pbuf, plen, parg))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 201 | return 0; never executed: return 0; | 0 |
| 202 | free(*pndef_aux); | - |
| 203 | *pndef_aux = NULL; | - |
| 204 | return 1; never executed: return 1; | 0 |
| 205 | } | - |
| 206 | | - |
| 207 | static int | - |
| 208 | ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | - |
| 209 | { | - |
| 210 | NDEF_SUPPORT *ndef_aux; | - |
| 211 | unsigned char *p; | - |
| 212 | int derlen; | - |
| 213 | const ASN1_AUX *aux; | - |
| 214 | ASN1_STREAM_ARG sarg; | - |
| 215 | | - |
| 216 | if (!parg)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 217 | return 0; never executed: return 0; | 0 |
| 218 | | - |
| 219 | ndef_aux = *(NDEF_SUPPORT **)parg; | - |
| 220 | | - |
| 221 | aux = ndef_aux->it->funcs; | - |
| 222 | | - |
| 223 | | - |
| 224 | sarg.ndef_bio = ndef_aux->ndef_bio; | - |
| 225 | sarg.out = ndef_aux->out; | - |
| 226 | sarg.boundary = ndef_aux->boundary; | - |
| 227 | if (aux->asn1_cb(ASN1_OP_STREAM_POST,| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 228 | &ndef_aux->val, ndef_aux->it, &sarg) <= 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 229 | return 0; never executed: return 0; | 0 |
| 230 | | - |
| 231 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); | - |
| 232 | p = malloc(derlen); | - |
| 233 | ndef_aux->derbuf = p; | - |
| 234 | *pbuf = p; | - |
| 235 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it); | - |
| 236 | | - |
| 237 | if (!*ndef_aux->boundary)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 238 | return 0; never executed: return 0; | 0 |
| 239 | *pbuf = *ndef_aux->boundary; | - |
| 240 | *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf); | - |
| 241 | | - |
| 242 | return 1; never executed: return 1; | 0 |
| 243 | } | - |
| | |