|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <stdio.h>
|
|
Packit Service |
084de1 |
#include "internal/cryptlib.h"
|
|
Packit Service |
084de1 |
#include <openssl/asn1.h>
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* ASN1 packing and unpacking functions */
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ASN1_STRING *octmp;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (oct == NULL || *oct == NULL) {
|
|
Packit Service |
084de1 |
if ((octmp = ASN1_STRING_new()) == NULL) {
|
|
Packit Service |
084de1 |
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
} else {
|
|
Packit Service |
084de1 |
octmp = *oct;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
OPENSSL_free(octmp->data);
|
|
Packit Service |
084de1 |
octmp->data = NULL;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if ((octmp->length = ASN1_item_i2d(obj, &octmp->data, it)) == 0) {
|
|
Packit Service |
084de1 |
ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR);
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (octmp->data == NULL) {
|
|
Packit Service |
084de1 |
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (oct != NULL && *oct == NULL)
|
|
Packit Service |
084de1 |
*oct = octmp;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
return octmp;
|
|
Packit Service |
084de1 |
err:
|
|
Packit Service |
084de1 |
if (oct == NULL || *oct == NULL)
|
|
Packit Service |
084de1 |
ASN1_STRING_free(octmp);
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* Extract an ASN1 object from an ASN1_STRING */
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
const unsigned char *p;
|
|
Packit Service |
084de1 |
void *ret;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
p = oct->data;
|
|
Packit Service |
084de1 |
if ((ret = ASN1_item_d2i(NULL, &p, oct->length, it)) == NULL)
|
|
Packit Service |
084de1 |
ASN1err(ASN1_F_ASN1_ITEM_UNPACK, ASN1_R_DECODE_ERROR);
|
|
Packit Service |
084de1 |
return ret;
|
|
Packit Service |
084de1 |
}
|