2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include <openssl/asn1.h>
13 #include <openssl/asn1t.h>
15 int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
19 if ((os = ASN1_OCTET_STRING_new()) == NULL)
21 if (!ASN1_OCTET_STRING_set(os, data, len)) {
22 ASN1_OCTET_STRING_free(os);
25 ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os);
29 /* int max_len: for returned value */
30 int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len)
33 const unsigned char *p;
35 if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) {
36 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG);
39 p = ASN1_STRING_get0_data(a->value.octet_string);
40 ret = ASN1_STRING_length(a->value.octet_string);
51 ASN1_OCTET_STRING *oct;
54 ASN1_SEQUENCE(asn1_int_oct) = {
55 ASN1_SIMPLE(asn1_int_oct, num, LONG),
56 ASN1_SIMPLE(asn1_int_oct, oct, ASN1_OCTET_STRING)
57 } static_ASN1_SEQUENCE_END(asn1_int_oct)
59 DECLARE_ASN1_ITEM(asn1_int_oct)
61 int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
65 ASN1_OCTET_STRING oct;
70 oct.type = V_ASN1_OCTET_STRING;
74 if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(asn1_int_oct), &atmp, &a))
80 * we return the actual length...
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)
86 asn1_int_oct *atmp = NULL;
89 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) {
93 atmp = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(asn1_int_oct), a);
101 ret = ASN1_STRING_length(atmp->oct);
108 memcpy(data, ASN1_STRING_get0_data(atmp->oct), n);
111 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, ASN1_R_DATA_IS_WRONG);
113 M_ASN1_free_of(atmp, asn1_int_oct);