libsaltpack
Loading...
Searching...
No Matches
MessageWriter.h
1/*
2 * Copyright 2016-2024 Luca Zanconato
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SALTPACK_MESSAGEWRITER_H
18#define SALTPACK_MESSAGEWRITER_H
19
20#include <list>
21#include "Base.h"
22
23namespace saltpack {
24
30 class MessageWriter : public Base {
31
32 public:
43 MessageWriter(std::ostream &os, BYTE_ARRAY senderSecretkey, const std::list<BYTE_ARRAY>& recipients,
44 bool visibleRecipients);
45
56 MessageWriter(std::ostream &os, BYTE_ARRAY senderSecretkey, const std::list<BYTE_ARRAY>& recipients);
57
67 MessageWriter(std::ostream &os, const std::list<BYTE_ARRAY>& recipients, bool visibleRecipients);
68
78 MessageWriter(std::ostream &os, const std::list<BYTE_ARRAY>& recipients);
79
89 MessageWriter(std::ostream &os, const BYTE_ARRAY& senderSecretkey, bool detatchedSignature);
90
103 MessageWriter(std::ostream &os, const BYTE_ARRAY& senderSecretkey, const std::list<BYTE_ARRAY>& recipientsPublickeys,
104 const std::list<std::pair<BYTE_ARRAY, BYTE_ARRAY>>& symmetricKeys);
105
118 MessageWriter(std::ostream &os, const std::list<BYTE_ARRAY>& recipientsPublickeys,
119 const std::list<std::pair<BYTE_ARRAY, BYTE_ARRAY>>& symmetricKeys);
120
124 ~MessageWriter() override;
125
134 void addBlock(BYTE_ARRAY data, bool final);
135
136 private:
137 std::ostream &output;
138 unsigned long packetIndex;
139 BYTE_ARRAY payloadKey;
140 BYTE_ARRAY headerHash;
141 std::list<BYTE_ARRAY> macKeys;
142 bool lastBlockAdded;
143
144 BYTE_ARRAY secretKey;
145 BYTE_ARRAY buffer;
146
147 std::string generateEncryptionHeader(BYTE_ARRAY ephemeralSecretkey, BYTE_ARRAY ephemeralPublickey,
148 BYTE_ARRAY senderPublickey, const std::list<BYTE_ARRAY>& recipientsPublickeys,
149 bool visibleRecipients);
150
151 static std::string generateSignatureHeader(BYTE_ARRAY senderPublickey, bool detatchedSignature);
152
153 std::string generateSigncryptionHeader(const BYTE_ARRAY& ephemeralSecretkey, const BYTE_ARRAY& ephemeralPublickey,
154 BYTE_ARRAY senderPublickey, const std::list<BYTE_ARRAY>& recipientsPublickeys,
155 const std::list<std::pair<BYTE_ARRAY, BYTE_ARRAY>>& symmetricKeys);
156
157 static std::string encodeHeader(const std::string& header);
158
159 static BYTE_ARRAY generateAuthenticator(BYTE_ARRAY concat, BYTE_ARRAY recipientMacKey);
160
161 std::string generatePayloadPacket(BYTE_ARRAY message, bool final);
162
163 std::string generateSignaturePayloadPacket(const BYTE_ARRAY& message, bool final);
164
165 std::string generateSigncryptionPayloadPacket(BYTE_ARRAY message, bool final);
166 };
167}
168
169#endif //SALTPACK_MESSAGEWRITER_H
The class used to encrypt or sign a message.
Definition MessageWriter.h:30
MessageWriter(std::ostream &os, const BYTE_ARRAY &senderSecretkey, const std::list< BYTE_ARRAY > &recipientsPublickeys, const std::list< std::pair< BYTE_ARRAY, BYTE_ARRAY > > &symmetricKeys)
MessageWriter(std::ostream &os, BYTE_ARRAY senderSecretkey, const std::list< BYTE_ARRAY > &recipients, bool visibleRecipients)
MessageWriter(std::ostream &os, const std::list< BYTE_ARRAY > &recipients, bool visibleRecipients)
void addBlock(BYTE_ARRAY data, bool final)
MessageWriter(std::ostream &os, const std::list< BYTE_ARRAY > &recipients)
MessageWriter(std::ostream &os, const std::list< BYTE_ARRAY > &recipientsPublickeys, const std::list< std::pair< BYTE_ARRAY, BYTE_ARRAY > > &symmetricKeys)
MessageWriter(std::ostream &os, BYTE_ARRAY senderSecretkey, const std::list< BYTE_ARRAY > &recipients)
MessageWriter(std::ostream &os, const BYTE_ARRAY &senderSecretkey, bool detatchedSignature)
The saltpack library namespace.
Definition ArmoredInputStream.h:24
std::vector< BYTE > BYTE_ARRAY
Definition types.h:30