| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/pkcs12/p12_attr.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||
| 2 | * Copyright 1999-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/pkcs12.h> | - | ||||||
| 13 | #include "p12_lcl.h" | - | ||||||
| 14 | - | |||||||
| 15 | /* Add a local keyid to a safebag */ | - | ||||||
| 16 | - | |||||||
| 17 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, | - | ||||||
| 18 | int namelen) | - | ||||||
| 19 | { | - | ||||||
| 20 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID,
| 0 | ||||||
| 21 | V_ASN1_OCTET_STRING, name, namelen))
| 0 | ||||||
| 22 | return 1; never executed: return 1; | 0 | ||||||
| 23 | else | - | ||||||
| 24 | return 0; never executed: return 0; | 0 | ||||||
| 25 | } | - | ||||||
| 26 | - | |||||||
| 27 | /* Add key usage to PKCS#8 structure */ | - | ||||||
| 28 | - | |||||||
| 29 | int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage) | - | ||||||
| 30 | { | - | ||||||
| 31 | unsigned char us_val = (unsigned char)usage; | - | ||||||
| 32 | return PKCS8_pkey_add1_attr_by_NID(p8, NID_key_usage, never executed: return PKCS8_pkey_add1_attr_by_NID(p8, 83, 3, &us_val, 1); | 0 | ||||||
| 33 | V_ASN1_BIT_STRING, &us_val, 1); never executed: return PKCS8_pkey_add1_attr_by_NID(p8, 83, 3, &us_val, 1); | 0 | ||||||
| 34 | } | - | ||||||
| 35 | - | |||||||
| 36 | /* Add a friendlyname to a safebag */ | - | ||||||
| 37 | - | |||||||
| 38 | int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, | - | ||||||
| 39 | int namelen) | - | ||||||
| 40 | { | - | ||||||
| 41 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
| 0 | ||||||
| 42 | MBSTRING_ASC, (unsigned char *)name, namelen))
| 0 | ||||||
| 43 | return 1; never executed: return 1; | 0 | ||||||
| 44 | else | - | ||||||
| 45 | return 0; never executed: return 0; | 0 | ||||||
| 46 | } | - | ||||||
| 47 | - | |||||||
| 48 | int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name, | - | ||||||
| 49 | int namelen) | - | ||||||
| 50 | { | - | ||||||
| 51 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
| 0 | ||||||
| 52 | MBSTRING_UTF8, (unsigned char *)name, namelen))
| 0 | ||||||
| 53 | return 1; never executed: return 1; | 0 | ||||||
| 54 | else | - | ||||||
| 55 | return 0; never executed: return 0; | 0 | ||||||
| 56 | } | - | ||||||
| 57 | - | |||||||
| 58 | int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, | - | ||||||
| 59 | const unsigned char *name, int namelen) | - | ||||||
| 60 | { | - | ||||||
| 61 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
| 0 | ||||||
| 62 | MBSTRING_BMP, name, namelen))
| 0 | ||||||
| 63 | return 1; never executed: return 1; | 0 | ||||||
| 64 | else | - | ||||||
| 65 | return 0; never executed: return 0; | 0 | ||||||
| 66 | } | - | ||||||
| 67 | - | |||||||
| 68 | int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, int namelen) | - | ||||||
| 69 | { | - | ||||||
| 70 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_ms_csp_name,
| 0 | ||||||
| 71 | MBSTRING_ASC, (unsigned char *)name, namelen))
| 0 | ||||||
| 72 | return 1; never executed: return 1; | 0 | ||||||
| 73 | else | - | ||||||
| 74 | return 0; never executed: return 0; | 0 | ||||||
| 75 | } | - | ||||||
| 76 | - | |||||||
| 77 | ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs, | - | ||||||
| 78 | int attr_nid) | - | ||||||
| 79 | { | - | ||||||
| 80 | X509_ATTRIBUTE *attrib; | - | ||||||
| 81 | int i; | - | ||||||
| 82 | i = X509at_get_attr_by_NID(attrs, attr_nid, -1); | - | ||||||
| 83 | attrib = X509at_get_attr(attrs, i); | - | ||||||
| 84 | return X509_ATTRIBUTE_get0_type(attrib, 0); never executed: return X509_ATTRIBUTE_get0_type(attrib, 0); | 0 | ||||||
| 85 | } | - | ||||||
| 86 | - | |||||||
| 87 | char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag) | - | ||||||
| 88 | { | - | ||||||
| 89 | const ASN1_TYPE *atype; | - | ||||||
| 90 | - | |||||||
| 91 | if ((atype = PKCS12_SAFEBAG_get0_attr(bag, NID_friendlyName)) == NULL)
| 0 | ||||||
| 92 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 93 | if (atype->type != V_ASN1_BMPSTRING)
| 0 | ||||||
| 94 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 95 | return OPENSSL_uni2utf8(atype->value.bmpstring->data, never executed: return OPENSSL_uni2utf8(atype->value.bmpstring->data, atype->value.bmpstring->length); | 0 | ||||||
| 96 | atype->value.bmpstring->length); never executed: return OPENSSL_uni2utf8(atype->value.bmpstring->data, atype->value.bmpstring->length); | 0 | ||||||
| 97 | } | - | ||||||
| 98 | - | |||||||
| 99 | const STACK_OF(X509_ATTRIBUTE) * | - | ||||||
| 100 | PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag) | - | ||||||
| 101 | { | - | ||||||
| 102 | return bag->attrib; executed 2 times by 1 test: return bag->attrib;Executed by:
| 2 | ||||||
| 103 | } | - | ||||||
| Source code | Switch to Preprocessed file |