encrypted_payload: Encrypted payload can be constructed from plaintext

This commit is contained in:
Tobias Brunner 2014-06-16 15:01:28 +02:00
parent 1e0d8f3ec0
commit edfd33455c
2 changed files with 38 additions and 0 deletions

View File

@ -585,6 +585,16 @@ METHOD(encrypted_payload_t, decrypt, status_t,
return parse(this, plain);
}
METHOD(encrypted_payload_t, decrypt_plain, status_t,
private_encrypted_payload_t *this, chunk_t assoc)
{
if (!this->encrypted.ptr)
{
return FAILED;
}
return parse(this, this->encrypted);
}
METHOD(encrypted_payload_t, decrypt_v1, status_t,
private_encrypted_payload_t *this, chunk_t iv)
{
@ -671,3 +681,20 @@ encrypted_payload_t *encrypted_payload_create(payload_type_t type)
return &this->public;
}
/*
* Described in header
*/
encrypted_payload_t *encrypted_payload_create_from_plain(payload_type_t next,
chunk_t plain)
{
private_encrypted_payload_t *this;
this = (private_encrypted_payload_t*)encrypted_payload_create(PLV2_ENCRYPTED);
this->public.decrypt = _decrypt_plain;
this->next_payload = next;
this->encrypted = plain;
compute_length(this);
return &this->public;
}

View File

@ -118,4 +118,15 @@ struct encrypted_payload_t {
*/
encrypted_payload_t *encrypted_payload_create(payload_type_t type);
/**
* Creates an encrypted payload with the given plain text data and next payload
* type.
*
* @param next next payload type
* @param plain plaintext data (gets adopted)
* @return encrypted_payload_t object
*/
encrypted_payload_t *encrypted_payload_create_from_plain(payload_type_t next,
chunk_t plain);
#endif /** ENCRYPTED_PAYLOAD_H_ @}*/