]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
encrypted_payload: Encrypted payload can be constructed from plaintext
authorTobias Brunner <tobias@strongswan.org>
Mon, 16 Jun 2014 13:01:28 +0000 (15:01 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 10 Oct 2014 07:31:17 +0000 (09:31 +0200)
src/libcharon/encoding/payloads/encrypted_payload.c
src/libcharon/encoding/payloads/encrypted_payload.h

index 431f7bb28b8c7f755a7f6e32c606a533e9f42898..c61fb86833797353b46e2eda2511229adf57ba4f 100644 (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;
+}
index 663360f8064fb68dabcb80112b55b6971a5b7f7b..be59e3c2d9e7a9b73d6ce531aa3369c613ab357f 100644 (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_ @}*/