| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/evp_asn1.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/asn1.h> | - | ||||||||||||
| 13 | #include <openssl/asn1t.h> | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | - | ||||||||||||
| 16 | { | - | ||||||||||||
| 17 | ASN1_STRING *os; | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | if ((os = ASN1_OCTET_STRING_new()) == NULL)
| 0-26 | ||||||||||||
| 20 | return 0; never executed: return 0; | 0 | ||||||||||||
| 21 | if (!ASN1_OCTET_STRING_set(os, data, len)) {
| 0-26 | ||||||||||||
| 22 | ASN1_OCTET_STRING_free(os); | - | ||||||||||||
| 23 | return 0; never executed: return 0; | 0 | ||||||||||||
| 24 | } | - | ||||||||||||
| 25 | ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os); | - | ||||||||||||
| 26 | return 1; executed 26 times by 1 test: return 1;Executed by:
| 26 | ||||||||||||
| 27 | } | - | ||||||||||||
| 28 | - | |||||||||||||
| 29 | /* int max_len: for returned value */ | - | ||||||||||||
| 30 | int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len) | - | ||||||||||||
| 31 | { | - | ||||||||||||
| 32 | int ret, num; | - | ||||||||||||
| 33 | const unsigned char *p; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) {
| 0-26 | ||||||||||||
| 36 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG); | - | ||||||||||||
| 37 | return -1; never executed: return -1; | 0 | ||||||||||||
| 38 | } | - | ||||||||||||
| 39 | p = ASN1_STRING_get0_data(a->value.octet_string); | - | ||||||||||||
| 40 | ret = ASN1_STRING_length(a->value.octet_string); | - | ||||||||||||
| 41 | if (ret < max_len)
| 0-26 | ||||||||||||
| 42 | num = ret; never executed: num = ret; | 0 | ||||||||||||
| 43 | else | - | ||||||||||||
| 44 | num = max_len; executed 26 times by 1 test: num = max_len;Executed by:
| 26 | ||||||||||||
| 45 | memcpy(data, p, num); | - | ||||||||||||
| 46 | return ret; executed 26 times by 1 test: return ret;Executed by:
| 26 | ||||||||||||
| 47 | } | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | typedef struct { | - | ||||||||||||
| 50 | int32_t num; | - | ||||||||||||
| 51 | ASN1_OCTET_STRING *oct; | - | ||||||||||||
| 52 | } asn1_int_oct; | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | ASN1_SEQUENCE(asn1_int_oct) = { | - | ||||||||||||
| 55 | ASN1_EMBED(asn1_int_oct, num, INT32), | - | ||||||||||||
| 56 | ASN1_SIMPLE(asn1_int_oct, oct, ASN1_OCTET_STRING) | - | ||||||||||||
| 57 | } static_ASN1_SEQUENCE_END(asn1_int_oct) | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | DECLARE_ASN1_ITEM(asn1_int_oct) | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | - | ||||||||||||
| 62 | int len) | - | ||||||||||||
| 63 | { | - | ||||||||||||
| 64 | asn1_int_oct atmp; | - | ||||||||||||
| 65 | ASN1_OCTET_STRING oct; | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | atmp.num = num; | - | ||||||||||||
| 68 | atmp.oct = &oct; | - | ||||||||||||
| 69 | oct.data = data; | - | ||||||||||||
| 70 | oct.type = V_ASN1_OCTET_STRING; | - | ||||||||||||
| 71 | oct.length = len; | - | ||||||||||||
| 72 | oct.flags = 0; | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(asn1_int_oct), &atmp, &a))
| 0-2 | ||||||||||||
| 75 | return 1; executed 2 times by 1 test: return 1;Executed by:
| 2 | ||||||||||||
| 76 | return 0; never executed: return 0; | 0 | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | /* | - | ||||||||||||
| 80 | * we return the actual length... | - | ||||||||||||
| 81 | */ | - | ||||||||||||
| 82 | /* int max_len: for returned value */ | - | ||||||||||||
| 83 | int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num, | - | ||||||||||||
| 84 | unsigned char *data, int max_len) | - | ||||||||||||
| 85 | { | - | ||||||||||||
| 86 | asn1_int_oct *atmp = NULL; | - | ||||||||||||
| 87 | int ret = -1, n; | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) {
| 0-2 | ||||||||||||
| 90 | goto err; never executed: goto err; | 0 | ||||||||||||
| 91 | } | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | atmp = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(asn1_int_oct), a); | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | if (atmp == NULL)
| 0-2 | ||||||||||||
| 96 | goto err; never executed: goto err; | 0 | ||||||||||||
| 97 | - | |||||||||||||
| 98 | if (num != NULL)
| 0-2 | ||||||||||||
| 99 | *num = atmp->num; executed 2 times by 1 test: *num = atmp->num;Executed by:
| 2 | ||||||||||||
| 100 | - | |||||||||||||
| 101 | ret = ASN1_STRING_length(atmp->oct); | - | ||||||||||||
| 102 | if (max_len > ret)
| 0-2 | ||||||||||||
| 103 | n = ret; never executed: n = ret; | 0 | ||||||||||||
| 104 | else | - | ||||||||||||
| 105 | n = max_len; executed 2 times by 1 test: n = max_len;Executed by:
| 2 | ||||||||||||
| 106 | - | |||||||||||||
| 107 | if (data != NULL)
| 0-2 | ||||||||||||
| 108 | memcpy(data, ASN1_STRING_get0_data(atmp->oct), n); executed 2 times by 1 test: memcpy(data, ASN1_STRING_get0_data(atmp->oct), n);Executed by:
| 2 | ||||||||||||
| 109 | if (ret == -1) {
| 0-2 | ||||||||||||
| 110 | err: | - | ||||||||||||
| 111 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, ASN1_R_DATA_IS_WRONG); | - | ||||||||||||
| 112 | } never executed: end of block | 0 | ||||||||||||
| 113 | M_ASN1_free_of(atmp, asn1_int_oct); | - | ||||||||||||
| 114 | return ret; executed 2 times by 1 test: return ret;Executed by:
| 2 | ||||||||||||
| 115 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |