- creation from encoded never failes
This commit is contained in:
@@ -130,7 +130,6 @@ static void destroy(private_identification_t *this)
|
|||||||
*/
|
*/
|
||||||
static private_identification_t *identification_create()
|
static private_identification_t *identification_create()
|
||||||
{
|
{
|
||||||
|
|
||||||
private_identification_t *this = allocator_alloc_thing(private_identification_t);
|
private_identification_t *this = allocator_alloc_thing(private_identification_t);
|
||||||
|
|
||||||
/* assign methods */
|
/* assign methods */
|
||||||
@@ -152,6 +151,7 @@ static private_identification_t *identification_create()
|
|||||||
identification_t *identification_create_from_string(id_type_t type, char *string)
|
identification_t *identification_create_from_string(id_type_t type, char *string)
|
||||||
{
|
{
|
||||||
private_identification_t *this = identification_create();
|
private_identification_t *this = identification_create();
|
||||||
|
|
||||||
this->type = type;
|
this->type = type;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@@ -192,36 +192,55 @@ identification_t *identification_create_from_string(id_type_t type, char *string
|
|||||||
identification_t *identification_create_from_encoding(id_type_t type, chunk_t encoded)
|
identification_t *identification_create_from_encoding(id_type_t type, chunk_t encoded)
|
||||||
{
|
{
|
||||||
private_identification_t *this = identification_create();
|
private_identification_t *this = identification_create();
|
||||||
|
|
||||||
|
this->encoded = allocator_clone_chunk(encoded);
|
||||||
|
|
||||||
this->type = type;
|
this->type = type;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ID_IPV4_ADDR:
|
case ID_IPV4_ADDR:
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
/* clone chunk */
|
|
||||||
if (encoded.len != 4)
|
|
||||||
{
|
|
||||||
allocator_free(this);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
this->encoded = allocator_clone_chunk(encoded);
|
|
||||||
tmp = inet_ntoa(*((struct in_addr*)(encoded.ptr)));
|
tmp = inet_ntoa(*((struct in_addr*)(encoded.ptr)));
|
||||||
/* build string, must be cloned */
|
/* build string, must be cloned */
|
||||||
this->string = allocator_alloc(strlen(tmp)+1);
|
this->string = allocator_alloc(strlen(tmp)+1);
|
||||||
strcpy(this->string, tmp);
|
strcpy(this->string, tmp);
|
||||||
return &(this->public);
|
|
||||||
}
|
}
|
||||||
case ID_IPV6_ADDR:
|
case ID_IPV6_ADDR:
|
||||||
|
{
|
||||||
|
this->string = "[ID_IPV6_ADDR]";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ID_FQDN:
|
case ID_FQDN:
|
||||||
|
{
|
||||||
|
this->string = "[ID_FQDN]";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ID_RFC822_ADDR:
|
case ID_RFC822_ADDR:
|
||||||
|
{
|
||||||
|
this->string = "[ID_RFC822_ADDR]";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ID_DER_ASN1_DN:
|
case ID_DER_ASN1_DN:
|
||||||
|
{
|
||||||
|
this->string = "[ID_DER_ASN1_DN]";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ID_DER_ASN1_GN:
|
case ID_DER_ASN1_GN:
|
||||||
|
{
|
||||||
|
this->string = "[ID_DER_ASN1_GN]";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ID_KEY_ID:
|
case ID_KEY_ID:
|
||||||
|
{
|
||||||
|
this->string = "[ID_KEY_ID]";
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
/* not supported */
|
this->string = "[unknown id_type_t]";
|
||||||
allocator_free(this);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &(this->public);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,8 @@ struct identification_t {
|
|||||||
*
|
*
|
||||||
* @param type type of this id, such as ID_IPV4_ADDR or ID_RFC822_ADDR
|
* @param type type of this id, such as ID_IPV4_ADDR or ID_RFC822_ADDR
|
||||||
* @param string input string, which will be converted
|
* @param string input string, which will be converted
|
||||||
* @return - created identification_t object, or
|
* @return
|
||||||
|
* - created identification_t object, or
|
||||||
* - NULL if type not supported.
|
* - NULL if type not supported.
|
||||||
*
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
@@ -165,8 +166,7 @@ identification_t * identification_create_from_string(id_type_t type, char *strin
|
|||||||
*
|
*
|
||||||
* @param type type of this id, such as ID_IPV4_ADDR or ID_RFC822_ADDR
|
* @param type type of this id, such as ID_IPV4_ADDR or ID_RFC822_ADDR
|
||||||
* @param encoded encoded bytes, such as from identification_t.get_encoding
|
* @param encoded encoded bytes, such as from identification_t.get_encoding
|
||||||
* @return - created identification_t object, or
|
* @return created identification_t object
|
||||||
* - NULL if type not supported.
|
|
||||||
*
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user