added generic implementation helpers for private_key_t.equals/belongs_to, public_key_t.equals
This commit is contained in:
@@ -15,3 +15,46 @@
|
||||
|
||||
#include "private_key.h"
|
||||
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
bool private_key_equals(private_key_t *this, private_key_t *other)
|
||||
{
|
||||
key_encoding_type_t type;
|
||||
chunk_t a, b;
|
||||
|
||||
if (this == other)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
for (type = 0; type < KEY_ENCODING_MAX; type++)
|
||||
{
|
||||
if (this->get_fingerprint(this, type, &a) &&
|
||||
other->get_fingerprint(other, type, &b))
|
||||
{
|
||||
return chunk_equals(a, b);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
bool private_key_belongs_to(private_key_t *private, public_key_t *public)
|
||||
{
|
||||
key_encoding_type_t type;
|
||||
chunk_t a, b;
|
||||
|
||||
for (type = 0; type < KEY_ENCODING_MAX; type++)
|
||||
{
|
||||
if (private->get_fingerprint(private, type, &a) &&
|
||||
public->get_fingerprint(public, type, &b))
|
||||
{
|
||||
return chunk_equals(a, b);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,9 +112,27 @@ struct private_key_t {
|
||||
private_key_t* (*get_ref)(private_key_t *this);
|
||||
|
||||
/**
|
||||
* Decrease refcount, destroy private_key if no more references.
|
||||
*/
|
||||
void (*destroy)(private_key_t *this);
|
||||
* Decrease refcount, destroy private_key if no more references.
|
||||
*/
|
||||
void (*destroy)(private_key_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic private key equals() implementation, usable by implementors.
|
||||
*
|
||||
* @param this first key to compare
|
||||
* @param other second key to compare
|
||||
* @return TRUE if this is equal to other
|
||||
*/
|
||||
bool private_key_equals(private_key_t *this, private_key_t *other);
|
||||
|
||||
/**
|
||||
* Generic private key belongs_to() implementation, usable by implementors.
|
||||
*
|
||||
* @param this first key to compare
|
||||
* @param other second key to compare
|
||||
* @return TRUE if this is equal to other
|
||||
*/
|
||||
bool private_key_belongs_to(private_key_t *private, public_key_t *public);
|
||||
|
||||
#endif /** PRIVATE_KEY_H_ @}*/
|
||||
|
||||
@@ -39,6 +39,30 @@ ENUM(signature_scheme_names, SIGN_UNKNOWN, SIGN_ECDSA_521,
|
||||
"ECDSA-521",
|
||||
);
|
||||
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
bool public_key_equals(public_key_t *this, public_key_t *other)
|
||||
{
|
||||
key_encoding_type_t type;
|
||||
chunk_t a, b;
|
||||
|
||||
if (this == other)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
for (type = 0; type < KEY_ENCODING_MAX; type++)
|
||||
{
|
||||
if (this->get_fingerprint(this, type, &a) &&
|
||||
other->get_fingerprint(other, type, &b))
|
||||
{
|
||||
return chunk_equals(a, b);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Defined in header.
|
||||
*/
|
||||
|
||||
@@ -168,6 +168,15 @@ struct public_key_t {
|
||||
void (*destroy)(public_key_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic public key equals() implementation, usable by implementors.
|
||||
*
|
||||
* @param this first key to compare
|
||||
* @param other second key to compare
|
||||
* @return TRUE if this is equal to other
|
||||
*/
|
||||
bool public_key_equals(public_key_t *this, public_key_t *other);
|
||||
|
||||
/**
|
||||
* Conversion of ASN.1 signature or hash OID to signature scheme.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user