add self encryption

This commit is contained in:
mrbesen 2023-11-26 19:38:31 +01:00
parent bc95a6e403
commit 7d9d5fad53
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 11 additions and 2 deletions

View File

@ -19,4 +19,5 @@ public:
private:
std::map<int64_t, std::string> chatKeyMap;
bool dirty = true;
std::string self;
};

View File

@ -35,6 +35,10 @@ std::string Crypt::encryptForChat(int64_t chat, const std::string& message) {
.setFDMode(Y::SubProcess::FD::ALL, Y::SubProcess::FDMode::Pipe)
;
if(!self.empty()) {
builder.addArgs({"--encrypt-to", self});
}
std::unique_ptr<Y::SubProcess> proc = builder.start();
std::string out;
@ -113,8 +117,12 @@ void Crypt::load() {
std::string key;
int64_t chat = 0;
in >> chat >> key;
if(chat && !key.empty()) {
chatKeyMap[chat] = key;
if(!key.empty()) {
if(chat == 0) {
self = key;
} else {
chatKeyMap[chat] = key;
}
}
}
dirty = false;