| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/a_type.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||||||||
| 2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||
| 3 | * | - | ||||||||||||||||||
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||
| 5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||
| 6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||
| 7 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||
| 8 | */ | - | ||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | #include <stdio.h> | - | ||||||||||||||||||
| 11 | #include "internal/cryptlib.h" | - | ||||||||||||||||||
| 12 | #include <openssl/asn1t.h> | - | ||||||||||||||||||
| 13 | #include <openssl/objects.h> | - | ||||||||||||||||||
| 14 | #include "asn1_locl.h" | - | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | int ASN1_TYPE_get(const ASN1_TYPE *a) | - | ||||||||||||||||||
| 17 | { | - | ||||||||||||||||||
| 18 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
| 3-61 | ||||||||||||||||||
| 19 | return a->type; executed 65 times by 1 test: return a->type;Executed by:
| 65 | ||||||||||||||||||
| 20 | else | - | ||||||||||||||||||
| 21 | return 0; executed 3 times by 1 test: return 0;Executed by:
| 3 | ||||||||||||||||||
| 22 | } | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) | - | ||||||||||||||||||
| 25 | { | - | ||||||||||||||||||
| 26 | if (a->value.ptr != NULL) {
| 0-232438 | ||||||||||||||||||
| 27 | ASN1_TYPE **tmp_a = &a; | - | ||||||||||||||||||
| 28 | asn1_primitive_free((ASN1_VALUE **)tmp_a, NULL, 0); | - | ||||||||||||||||||
| 29 | } never executed: end of block | 0 | ||||||||||||||||||
| 30 | a->type = type; | - | ||||||||||||||||||
| 31 | if (type == V_ASN1_BOOLEAN)
| 1086-231352 | ||||||||||||||||||
| 32 | a->value.boolean = value ? 0xff : 0; executed 1086 times by 1 test: a->value.boolean = value ? 0xff : 0;Executed by:
| 0-1086 | ||||||||||||||||||
| 33 | else | - | ||||||||||||||||||
| 34 | a->value.ptr = value; executed 231352 times by 1 test: a->value.ptr = value;Executed by:
| 231352 | ||||||||||||||||||
| 35 | } | - | ||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) | - | ||||||||||||||||||
| 38 | { | - | ||||||||||||||||||
| 39 | if (!value || (type == V_ASN1_BOOLEAN)) {
| 0-104 | ||||||||||||||||||
| 40 | void *p = (void *)value; | - | ||||||||||||||||||
| 41 | ASN1_TYPE_set(a, type, p); | - | ||||||||||||||||||
| 42 | } else if (type == V_ASN1_OBJECT) { never executed: end of block
| 0-54 | ||||||||||||||||||
| 43 | ASN1_OBJECT *odup; | - | ||||||||||||||||||
| 44 | odup = OBJ_dup(value); | - | ||||||||||||||||||
| 45 | if (!odup)
| 0-50 | ||||||||||||||||||
| 46 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 47 | ASN1_TYPE_set(a, type, odup); | - | ||||||||||||||||||
| 48 | } else { executed 50 times by 1 test: end of blockExecuted by:
| 50 | ||||||||||||||||||
| 49 | ASN1_STRING *sdup; | - | ||||||||||||||||||
| 50 | sdup = ASN1_STRING_dup(value); | - | ||||||||||||||||||
| 51 | if (!sdup)
| 0-54 | ||||||||||||||||||
| 52 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 53 | ASN1_TYPE_set(a, type, sdup); | - | ||||||||||||||||||
| 54 | } executed 54 times by 1 test: end of blockExecuted by:
| 54 | ||||||||||||||||||
| 55 | return 1; executed 104 times by 1 test: return 1;Executed by:
| 104 | ||||||||||||||||||
| 56 | } | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | /* Returns 0 if they are equal, != 0 otherwise. */ | - | ||||||||||||||||||
| 59 | int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b) | - | ||||||||||||||||||
| 60 | { | - | ||||||||||||||||||
| 61 | int result = -1; | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | if (!a || !b || a->type != b->type)
| 0-1258 | ||||||||||||||||||
| 64 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | switch (a->type) { | - | ||||||||||||||||||
| 67 | case V_ASN1_OBJECT: never executed: case 6: | 0 | ||||||||||||||||||
| 68 | result = OBJ_cmp(a->value.object, b->value.object); | - | ||||||||||||||||||
| 69 | break; never executed: break; | 0 | ||||||||||||||||||
| 70 | case V_ASN1_BOOLEAN: never executed: case 1: | 0 | ||||||||||||||||||
| 71 | result = a->value.boolean - b->value.boolean; | - | ||||||||||||||||||
| 72 | break; never executed: break; | 0 | ||||||||||||||||||
| 73 | case V_ASN1_NULL: executed 1255 times by 1 test: case 5:Executed by:
| 1255 | ||||||||||||||||||
| 74 | result = 0; /* They do not have content. */ | - | ||||||||||||||||||
| 75 | break; executed 1255 times by 1 test: break;Executed by:
| 1255 | ||||||||||||||||||
| 76 | case V_ASN1_INTEGER: never executed: case 2: | 0 | ||||||||||||||||||
| 77 | case V_ASN1_ENUMERATED: never executed: case 10: | 0 | ||||||||||||||||||
| 78 | case V_ASN1_BIT_STRING: never executed: case 3: | 0 | ||||||||||||||||||
| 79 | case V_ASN1_OCTET_STRING: never executed: case 4: | 0 | ||||||||||||||||||
| 80 | case V_ASN1_SEQUENCE: executed 3 times by 1 test: case 16:Executed by:
| 3 | ||||||||||||||||||
| 81 | case V_ASN1_SET: never executed: case 17: | 0 | ||||||||||||||||||
| 82 | case V_ASN1_NUMERICSTRING: never executed: case 18: | 0 | ||||||||||||||||||
| 83 | case V_ASN1_PRINTABLESTRING: never executed: case 19: | 0 | ||||||||||||||||||
| 84 | case V_ASN1_T61STRING: never executed: case 20: | 0 | ||||||||||||||||||
| 85 | case V_ASN1_VIDEOTEXSTRING: never executed: case 21: | 0 | ||||||||||||||||||
| 86 | case V_ASN1_IA5STRING: never executed: case 22: | 0 | ||||||||||||||||||
| 87 | case V_ASN1_UTCTIME: never executed: case 23: | 0 | ||||||||||||||||||
| 88 | case V_ASN1_GENERALIZEDTIME: never executed: case 24: | 0 | ||||||||||||||||||
| 89 | case V_ASN1_GRAPHICSTRING: never executed: case 25: | 0 | ||||||||||||||||||
| 90 | case V_ASN1_VISIBLESTRING: never executed: case 26: | 0 | ||||||||||||||||||
| 91 | case V_ASN1_GENERALSTRING: never executed: case 27: | 0 | ||||||||||||||||||
| 92 | case V_ASN1_UNIVERSALSTRING: never executed: case 28: | 0 | ||||||||||||||||||
| 93 | case V_ASN1_BMPSTRING: never executed: case 30: | 0 | ||||||||||||||||||
| 94 | case V_ASN1_UTF8STRING: never executed: case 12: | 0 | ||||||||||||||||||
| 95 | case V_ASN1_OTHER: never executed: case -3: | 0 | ||||||||||||||||||
| 96 | default: never executed: default: | 0 | ||||||||||||||||||
| 97 | result = ASN1_STRING_cmp((ASN1_STRING *)a->value.ptr, | - | ||||||||||||||||||
| 98 | (ASN1_STRING *)b->value.ptr); | - | ||||||||||||||||||
| 99 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 100 | } | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | return result; executed 1258 times by 1 test: return result;Executed by:
| 1258 | ||||||||||||||||||
| 103 | } | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t) | - | ||||||||||||||||||
| 106 | { | - | ||||||||||||||||||
| 107 | ASN1_OCTET_STRING *oct; | - | ||||||||||||||||||
| 108 | ASN1_TYPE *rt; | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | oct = ASN1_item_pack(s, it, NULL); | - | ||||||||||||||||||
| 111 | if (oct == NULL)
| 0-2 | ||||||||||||||||||
| 112 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | if (t && *t) {
| 0-2 | ||||||||||||||||||
| 115 | rt = *t; | - | ||||||||||||||||||
| 116 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 117 | rt = ASN1_TYPE_new(); | - | ||||||||||||||||||
| 118 | if (rt == NULL) {
| 0 | ||||||||||||||||||
| 119 | ASN1_OCTET_STRING_free(oct); | - | ||||||||||||||||||
| 120 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 121 | } | - | ||||||||||||||||||
| 122 | if (t)
| 0 | ||||||||||||||||||
| 123 | *t = rt; never executed: *t = rt; | 0 | ||||||||||||||||||
| 124 | } never executed: end of block | 0 | ||||||||||||||||||
| 125 | ASN1_TYPE_set(rt, V_ASN1_SEQUENCE, oct); | - | ||||||||||||||||||
| 126 | return rt; executed 2 times by 1 test: return rt;Executed by:
| 2 | ||||||||||||||||||
| 127 | } | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t) | - | ||||||||||||||||||
| 130 | { | - | ||||||||||||||||||
| 131 | if (t == NULL || t->type != V_ASN1_SEQUENCE || t->value.sequence == NULL)
| 0-306 | ||||||||||||||||||
| 132 | return NULL; executed 63 times by 1 test: return ((void *)0) ;Executed by:
| 63 | ||||||||||||||||||
| 133 | return ASN1_item_unpack(t->value.sequence, it); executed 250 times by 1 test: return ASN1_item_unpack(t->value.sequence, it);Executed by:
| 250 | ||||||||||||||||||
| 134 | } | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |