Public/Private keys implement a has_fingerprint() method

This commit is contained in:
Martin Willi
2009-09-21 16:47:25 +02:00
parent fde7f5abf8
commit 640ed4d5a5
14 changed files with 83 additions and 0 deletions
@@ -72,6 +72,8 @@ enum key_encoding_type_t {
/** PGPv4 fingerprint */
KEY_ID_PGPV4,
KEY_ID_MAX,
/** PKCS#1 and similar ASN.1 key encoding */
KEY_PUB_ASN1_DER,
KEY_PRIV_ASN1_DER,
@@ -58,3 +58,22 @@ bool private_key_belongs_to(private_key_t *private, public_key_t *public)
return FALSE;
}
/**
* See header.
*/
bool private_key_has_fingerprint(private_key_t *private, chunk_t fingerprint)
{
key_encoding_type_t type;
chunk_t current;
for (type = 0; type < KEY_ID_MAX; type++)
{
if (private->get_fingerprint(private, type, &current) &&
chunk_equals(current, fingerprint))
{
return TRUE;
}
}
return FALSE;
}
@@ -96,6 +96,14 @@ struct private_key_t {
bool (*get_fingerprint)(private_key_t *this, key_encoding_type_t type,
chunk_t *fp);
/**
* Check if a key has a given fingerprint of any kind.
*
* @param fp fingerprint to check
* @return TRUE if key has given fingerprint
*/
bool (*has_fingerprint)(private_key_t *this, chunk_t fp);
/**
* Get the key in an encoded form as a chunk.
*
@@ -137,4 +145,13 @@ bool private_key_equals(private_key_t *this, private_key_t *other);
*/
bool private_key_belongs_to(private_key_t *private, public_key_t *public);
/**
* Generic private key has_fingerprint() implementation, usable by implementors.
*
* @param this key to check fingerprint
* @param fp fingerprint to check
* @return TRUE if key has given fingerprint
*/
bool private_key_has_fingerprint(private_key_t *this, chunk_t fingerprint);
#endif /** PRIVATE_KEY_H_ @}*/
@@ -66,6 +66,25 @@ bool public_key_equals(public_key_t *this, public_key_t *other)
return FALSE;
}
/**
* See header.
*/
bool public_key_has_fingerprint(public_key_t *public, chunk_t fingerprint)
{
key_encoding_type_t type;
chunk_t current;
for (type = 0; type < KEY_ID_MAX; type++)
{
if (public->get_fingerprint(public, type, &current) &&
chunk_equals(current, fingerprint))
{
return TRUE;
}
}
return FALSE;
}
/*
* Defined in header.
*/
@@ -154,6 +154,14 @@ struct public_key_t {
bool (*get_fingerprint)(public_key_t *this, key_encoding_type_t type,
chunk_t *fp);
/**
* Check if a key has a given fingerprint of any kind.
*
* @param fp fingerprint to check
* @return TRUE if key has given fingerprint
*/
bool (*has_fingerprint)(public_key_t *this, chunk_t fp);
/**
* Get the key in an encoded form as a chunk.
*
@@ -186,6 +194,15 @@ struct public_key_t {
*/
bool public_key_equals(public_key_t *this, public_key_t *other);
/**
* Generic public key has_fingerprint() implementation, usable by implementors.
*
* @param this key to check fingerprint
* @param fp fingerprint to check
* @return TRUE if key has given fingerprint
*/
bool public_key_has_fingerprint(public_key_t *this, chunk_t fingerprint);
/**
* Conversion of ASN.1 signature or hash OID to signature scheme.
*