botan: Replace calls to deprecated botan_privkey|pubkey_export()
This commit is contained in:
@@ -114,16 +114,6 @@ static bool get_rng(private_key_exchange_t *this, botan_rng_t *rng)
|
|||||||
return botan_get_rng(rng, RNG_STRONG);
|
return botan_get_rng(rng, RNG_STRONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the given "view" to a chunk.
|
|
||||||
*/
|
|
||||||
CALLBACK(botan_view_to_chunk, int,
|
|
||||||
chunk_t *chunk, const uint8_t *data, size_t len)
|
|
||||||
{
|
|
||||||
*chunk = chunk_clone(chunk_create((u_char*)data, len));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a key pair as initiator.
|
* Generate a key pair as initiator.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -48,6 +48,26 @@ bool chunk_to_botan_mp(chunk_t value, botan_mp_t *mp)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Described in header
|
||||||
|
*/
|
||||||
|
int botan_view_to_chunk(botan_view_ctx ctx, const uint8_t *data, size_t len)
|
||||||
|
{
|
||||||
|
chunk_t *chunk = (chunk_t*)ctx;
|
||||||
|
|
||||||
|
*chunk = chunk_clone(chunk_create((u_char*)data, len));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version of the above for PEM version of the view functions.
|
||||||
|
*/
|
||||||
|
static int botan_view_str_to_chunk(botan_view_ctx ctx, const char *data,
|
||||||
|
size_t len)
|
||||||
|
{
|
||||||
|
return botan_view_to_chunk(ctx, (const uint8_t*)data, len);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Described in header
|
* Described in header
|
||||||
*/
|
*/
|
||||||
@@ -121,21 +141,11 @@ bool botan_get_encoding(botan_pubkey_t pubkey, cred_encoding_type_t type,
|
|||||||
bool success = FALSE;
|
bool success = FALSE;
|
||||||
|
|
||||||
encoding->len = 0;
|
encoding->len = 0;
|
||||||
if (botan_pubkey_export(pubkey, NULL, &encoding->len,
|
if (botan_pubkey_view_der(pubkey, encoding, botan_view_to_chunk))
|
||||||
BOTAN_PRIVKEY_EXPORT_FLAG_DER)
|
|
||||||
!= BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE)
|
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*encoding = chunk_alloc(encoding->len);
|
|
||||||
if (botan_pubkey_export(pubkey, encoding->ptr, &encoding->len,
|
|
||||||
BOTAN_PRIVKEY_EXPORT_FLAG_DER))
|
|
||||||
{
|
|
||||||
chunk_free(encoding);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == PUBKEY_SPKI_ASN1_DER)
|
if (type == PUBKEY_SPKI_ASN1_DER)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -182,28 +192,12 @@ bool botan_get_encoding(botan_pubkey_t pubkey, cred_encoding_type_t type,
|
|||||||
bool botan_get_privkey_encoding(botan_privkey_t key, cred_encoding_type_t type,
|
bool botan_get_privkey_encoding(botan_privkey_t key, cred_encoding_type_t type,
|
||||||
chunk_t *encoding)
|
chunk_t *encoding)
|
||||||
{
|
{
|
||||||
uint32_t format = BOTAN_PRIVKEY_EXPORT_FLAG_DER;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case PRIVKEY_PEM:
|
case PRIVKEY_PEM:
|
||||||
format = BOTAN_PRIVKEY_EXPORT_FLAG_PEM;
|
return !botan_privkey_view_pem(key, encoding, botan_view_str_to_chunk);
|
||||||
/* fall-through */
|
|
||||||
case PRIVKEY_ASN1_DER:
|
case PRIVKEY_ASN1_DER:
|
||||||
encoding->len = 0;
|
return !botan_privkey_view_der(key, encoding, botan_view_to_chunk);
|
||||||
if (botan_privkey_export(key, NULL, &encoding->len, format)
|
|
||||||
!= BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
*encoding = chunk_alloc(encoding->len);
|
|
||||||
if (botan_privkey_export(key, encoding->ptr, &encoding->len,
|
|
||||||
format))
|
|
||||||
{
|
|
||||||
chunk_free(encoding);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,17 @@
|
|||||||
*/
|
*/
|
||||||
bool chunk_to_botan_mp(chunk_t value, botan_mp_t *mp);
|
bool chunk_to_botan_mp(chunk_t value, botan_mp_t *mp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for botan_pubkey_view_*() to convert the data to an allocated
|
||||||
|
* chunk.
|
||||||
|
*
|
||||||
|
* @param ctx pointer to the resulting chunk
|
||||||
|
* @param data "viewed" data
|
||||||
|
* @param len length of data
|
||||||
|
* @return 0 if successful
|
||||||
|
*/
|
||||||
|
int botan_view_to_chunk(botan_view_ctx ctx, const uint8_t *data, size_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Botan string identifier for the given hash algorithm.
|
* Get the Botan string identifier for the given hash algorithm.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user