identification: Add hash() method
Compared to hashing the encoding we can ignore string types of RDNs when hashing DNs, making hash() compatible to equals() that does the same. Fixes #991.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2012 Tobias Brunner
|
||||
* Copyright (C) 2009-2015 Tobias Brunner
|
||||
* Copyright (C) 2005-2009 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
@@ -579,6 +579,19 @@ METHOD(identification_t, contains_wildcards_memchr, bool,
|
||||
return memchr(this->encoded.ptr, '*', this->encoded.len) != NULL;
|
||||
}
|
||||
|
||||
METHOD(identification_t, hash_binary, u_int,
|
||||
private_identification_t *this, u_int inc)
|
||||
{
|
||||
u_int hash;
|
||||
|
||||
hash = chunk_hash_inc(chunk_from_thing(this->type), inc);
|
||||
if (this->type != ID_ANY)
|
||||
{
|
||||
hash = chunk_hash_inc(this->encoded, hash);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
METHOD(identification_t, equals_binary, bool,
|
||||
private_identification_t *this, identification_t *other)
|
||||
{
|
||||
@@ -687,6 +700,24 @@ METHOD(identification_t, equals_dn, bool,
|
||||
return compare_dn(this->encoded, other->get_encoding(other), NULL);
|
||||
}
|
||||
|
||||
METHOD(identification_t, hash_dn, u_int,
|
||||
private_identification_t *this, u_int inc)
|
||||
{
|
||||
enumerator_t *rdns;
|
||||
chunk_t oid, data;
|
||||
u_char type;
|
||||
u_int hash;
|
||||
|
||||
hash = chunk_hash_inc(chunk_from_thing(this->type), inc);
|
||||
rdns = create_rdn_enumerator(this->encoded);
|
||||
while (rdns->enumerate(rdns, &oid, &type, &data))
|
||||
{
|
||||
hash = chunk_hash_inc(data, chunk_hash_inc(oid, hash));
|
||||
}
|
||||
rdns->destroy(rdns);
|
||||
return hash;
|
||||
}
|
||||
|
||||
METHOD(identification_t, equals_strcasecmp, bool,
|
||||
private_identification_t *this, identification_t *other)
|
||||
{
|
||||
@@ -903,6 +934,7 @@ static private_identification_t *identification_create(id_type_t type)
|
||||
switch (type)
|
||||
{
|
||||
case ID_ANY:
|
||||
this->public.hash = _hash_binary;
|
||||
this->public.matches = _matches_any;
|
||||
this->public.equals = _equals_binary;
|
||||
this->public.contains_wildcards = return_true;
|
||||
@@ -910,16 +942,19 @@ static private_identification_t *identification_create(id_type_t type)
|
||||
case ID_FQDN:
|
||||
case ID_RFC822_ADDR:
|
||||
case ID_USER_ID:
|
||||
this->public.hash = _hash_binary;
|
||||
this->public.matches = _matches_string;
|
||||
this->public.equals = _equals_strcasecmp;
|
||||
this->public.contains_wildcards = _contains_wildcards_memchr;
|
||||
break;
|
||||
case ID_DER_ASN1_DN:
|
||||
this->public.hash = _hash_dn;
|
||||
this->public.equals = _equals_dn;
|
||||
this->public.matches = _matches_dn;
|
||||
this->public.contains_wildcards = _contains_wildcards_dn;
|
||||
break;
|
||||
default:
|
||||
this->public.hash = _hash_binary;
|
||||
this->public.equals = _equals_binary;
|
||||
this->public.matches = _matches_binary;
|
||||
this->public.contains_wildcards = return_false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Tobias Brunner
|
||||
* Copyright (C) 2009-2015 Tobias Brunner
|
||||
* Copyright (C) 2005-2009 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
@@ -218,6 +218,14 @@ struct identification_t {
|
||||
*/
|
||||
id_type_t (*get_type) (identification_t *this);
|
||||
|
||||
/**
|
||||
* Create a hash value for this identification_t object.
|
||||
*
|
||||
* @param inc optional value for incremental hashing
|
||||
* @return hash value
|
||||
*/
|
||||
u_int (*hash) (identification_t *this, u_int inc);
|
||||
|
||||
/**
|
||||
* Check if two identification_t objects are equal.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user