libsaltpack
Loading...
Searching...
No Matches
MessageReader.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_MESSAGEREADER_H
18#define SALTPACK_MESSAGEREADER_H
19
20#include <msgpack.hpp>
21#include "Base.h"
22#include "PayloadPacket.h"
23#include "PayloadPacketV2.h"
24#include "SignaturePayloadPacket.h"
25
26namespace saltpack {
27
33 class MessageReader : public Base {
34
35 public:
44 MessageReader(std::istream &is, const BYTE_ARRAY& recipientSecretkey);
45
53 explicit MessageReader(std::istream &is);
54
63 MessageReader(std::istream &is, std::istream &messageStream);
64
77 MessageReader(std::istream &is, const BYTE_ARRAY& recipientSecretkey, const std::pair<BYTE_ARRAY, BYTE_ARRAY>& symmetricKey);
78
82 ~MessageReader() override;
83
92
101
110 std::list<BYTE_ARRAY> getRecipients();
111
118
127
128 private:
129 BYTE_ARRAY headerHash;
130 BYTE_ARRAY payloadKey;
131 BYTE_ARRAY macKey;
132 unsigned long recipientIndex{};
133 std::list<BYTE_ARRAY> recipients;
134 unsigned long packetIndex{};
135 std::istream &input;
136 msgpack::unpacker unpacker;
137 bool lastBlockFound{};
138 bool intentionallyAnonymous{};
139 int majorVersion{};
140 int minorVersion{};
141
142 BYTE_ARRAY senderPublickey;
143
144 void processEncryptionHeader(std::vector<char> headerBin, BYTE_ARRAY recipientSecretkey);
145
146 void processSignatureHeader(std::vector<char> headerBin);
147
148 void processSigncryptionHeader(std::vector<char> headerBin, const BYTE_ARRAY& recipientSecretkey,
149 const std::pair<BYTE_ARRAY, BYTE_ARRAY>& symmetricKey);
150
151 BYTE_ARRAY decryptPacket(std::vector<BYTE_ARRAY> authenticatorsList, BYTE_ARRAY payloadSecretbox, bool final);
152
153 BYTE_ARRAY verifyPacket(BYTE_ARRAY signature, BYTE_ARRAY payloadChunk, bool final);
154
155 BYTE_ARRAY decryptPacket(BYTE_ARRAY payloadSecretbox, bool final);
156 };
157}
158
159#endif //SALTPACK_MESSAGEREADER_H
The class used to decrypt or verify a message.
Definition MessageReader.h:33
std::list< BYTE_ARRAY > getRecipients()
MessageReader(std::istream &is)
MessageReader(std::istream &is, const BYTE_ARRAY &recipientSecretkey)
MessageReader(std::istream &is, std::istream &messageStream)
MessageReader(std::istream &is, const BYTE_ARRAY &recipientSecretkey, const std::pair< BYTE_ARRAY, BYTE_ARRAY > &symmetricKey)
The saltpack library namespace.
Definition ArmoredInputStream.h:24
std::vector< BYTE > BYTE_ARRAY
Definition types.h:30