Migrated crypto/pkcs9 to INIT/METHOD macros
This commit is contained in:
@@ -182,21 +182,22 @@ static void attribute_destroy(attribute_t *this)
|
|||||||
*/
|
*/
|
||||||
static attribute_t *attribute_create(int oid, chunk_t value)
|
static attribute_t *attribute_create(int oid, chunk_t value)
|
||||||
{
|
{
|
||||||
attribute_t *this = malloc_thing(attribute_t);
|
attribute_t *this;
|
||||||
|
|
||||||
|
INIT(this,
|
||||||
|
.destroy = attribute_destroy,
|
||||||
|
.oid = oid,
|
||||||
|
.value = chunk_clone(value),
|
||||||
|
.encoding = asn1_wrap(ASN1_SEQUENCE, "cm",
|
||||||
|
asn1_attributeIdentifier(oid),
|
||||||
|
asn1_simple_object(ASN1_SET, value)),
|
||||||
|
);
|
||||||
|
|
||||||
this->oid = oid;
|
|
||||||
this->value = chunk_clone(value);
|
|
||||||
this->encoding = asn1_wrap(ASN1_SEQUENCE, "cm",
|
|
||||||
asn1_attributeIdentifier(oid),
|
|
||||||
asn1_simple_object(ASN1_SET, value));
|
|
||||||
this->destroy = (void (*) (attribute_t*))attribute_destroy;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(pkcs9_t, build_encoding, void,
|
||||||
* Implements pkcs9_t.build_encoding
|
private_pkcs9_t *this)
|
||||||
*/
|
|
||||||
static void build_encoding(private_pkcs9_t *this)
|
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
attribute_t *attribute;
|
attribute_t *attribute;
|
||||||
@@ -235,10 +236,8 @@ static void build_encoding(private_pkcs9_t *this)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(pkcs9_t, get_encoding, chunk_t,
|
||||||
* Implements pkcs9_t.get_encoding
|
private_pkcs9_t *this)
|
||||||
*/
|
|
||||||
static chunk_t get_encoding(private_pkcs9_t *this)
|
|
||||||
{
|
{
|
||||||
if (this->encoding.ptr == NULL)
|
if (this->encoding.ptr == NULL)
|
||||||
{
|
{
|
||||||
@@ -247,10 +246,8 @@ static chunk_t get_encoding(private_pkcs9_t *this)
|
|||||||
return this->encoding;
|
return this->encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(pkcs9_t, get_attribute, chunk_t,
|
||||||
* Implements pkcs9_t.get_attribute
|
private_pkcs9_t *this, int oid)
|
||||||
*/
|
|
||||||
static chunk_t get_attribute(private_pkcs9_t *this, int oid)
|
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
chunk_t value = chunk_empty;
|
chunk_t value = chunk_empty;
|
||||||
@@ -269,20 +266,16 @@ static chunk_t get_attribute(private_pkcs9_t *this, int oid)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(pkcs9_t, set_attribute, void,
|
||||||
* Implements pkcs9_t.set_attribute
|
private_pkcs9_t *this, int oid, chunk_t value)
|
||||||
*/
|
|
||||||
static void set_attribute(private_pkcs9_t *this, int oid, chunk_t value)
|
|
||||||
{
|
{
|
||||||
attribute_t *attribute = attribute_create(oid, value);
|
attribute_t *attribute = attribute_create(oid, value);
|
||||||
|
|
||||||
this->attributes->insert_last(this->attributes, (void*)attribute);
|
this->attributes->insert_last(this->attributes, (void*)attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(pkcs9_t, get_messageDigest, chunk_t,
|
||||||
* Implements pkcs9_t.get_messageDigest
|
private_pkcs9_t *this)
|
||||||
*/
|
|
||||||
static chunk_t get_messageDigest(private_pkcs9_t *this)
|
|
||||||
{
|
{
|
||||||
const int oid = OID_PKCS9_MESSAGE_DIGEST;
|
const int oid = OID_PKCS9_MESSAGE_DIGEST;
|
||||||
chunk_t value = get_attribute(this, oid);
|
chunk_t value = get_attribute(this, oid);
|
||||||
@@ -299,10 +292,8 @@ static chunk_t get_messageDigest(private_pkcs9_t *this)
|
|||||||
return chunk_clone(value);
|
return chunk_clone(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(pkcs9_t, set_messageDigest, void,
|
||||||
* Implements pkcs9_t.set_attribute
|
private_pkcs9_t *this, chunk_t value)
|
||||||
*/
|
|
||||||
static void set_messageDigest(private_pkcs9_t *this, chunk_t value)
|
|
||||||
{
|
{
|
||||||
const int oid = OID_PKCS9_MESSAGE_DIGEST;
|
const int oid = OID_PKCS9_MESSAGE_DIGEST;
|
||||||
chunk_t messageDigest = asn1_simple_object(asn1_attributeType(oid), value);
|
chunk_t messageDigest = asn1_simple_object(asn1_attributeType(oid), value);
|
||||||
@@ -311,10 +302,8 @@ static void set_messageDigest(private_pkcs9_t *this, chunk_t value)
|
|||||||
free(messageDigest.ptr);
|
free(messageDigest.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(pkcs9_t, destroy, void,
|
||||||
* Implements pkcs9_t.destroy
|
private_pkcs9_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_pkcs9_t *this)
|
|
||||||
{
|
{
|
||||||
this->attributes->destroy_offset(this->attributes, offsetof(attribute_t, destroy));
|
this->attributes->destroy_offset(this->attributes, offsetof(attribute_t, destroy));
|
||||||
free(this->encoding.ptr);
|
free(this->encoding.ptr);
|
||||||
@@ -326,20 +315,20 @@ static void destroy(private_pkcs9_t *this)
|
|||||||
*/
|
*/
|
||||||
static private_pkcs9_t *pkcs9_create_empty(void)
|
static private_pkcs9_t *pkcs9_create_empty(void)
|
||||||
{
|
{
|
||||||
private_pkcs9_t *this = malloc_thing(private_pkcs9_t);
|
private_pkcs9_t *this;
|
||||||
|
|
||||||
/* initialize */
|
INIT(this,
|
||||||
this->encoding = chunk_empty;
|
.public = {
|
||||||
this->attributes = linked_list_create();
|
.build_encoding = _build_encoding,
|
||||||
|
.get_encoding = _get_encoding,
|
||||||
/*public functions */
|
.get_attribute = _get_attribute,
|
||||||
this->public.build_encoding = (void (*) (pkcs9_t*))build_encoding;
|
.set_attribute = _set_attribute,
|
||||||
this->public.get_encoding = (chunk_t (*) (pkcs9_t*))get_encoding;
|
.get_messageDigest = _get_messageDigest,
|
||||||
this->public.get_attribute = (chunk_t (*) (pkcs9_t*,int))get_attribute;
|
.set_messageDigest = _set_messageDigest,
|
||||||
this->public.set_attribute = (void (*) (pkcs9_t*,int,chunk_t))set_attribute;
|
.destroy = _destroy,
|
||||||
this->public.get_messageDigest = (chunk_t (*) (pkcs9_t*))get_messageDigest;
|
},
|
||||||
this->public.set_messageDigest = (void (*) (pkcs9_t*,chunk_t))set_messageDigest;
|
.attributes = linked_list_create(),
|
||||||
this->public.destroy = (void (*) (pkcs9_t*))destroy;
|
);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user