ThrowErr(Exc::Crypto::OperationNotSupported);
}
+RawBuffer AKey::getBinary() const
+{
+ if (m_type.isKeyPublic() && m_raw.empty())
+ m_raw = Internals::getData(getId(), getPassword());
+
+ return m_raw;
+}
+
RawBuffer AKey::sign(
const CryptoAlgorithm &alg,
const RawBuffer &message)
int m_scheme;
Pwd m_password;
RawBuffer m_id;
- RawBuffer m_raw;
+ mutable RawBuffer m_raw;
};
class Key : public BData {
int scheme,
RawBuffer id,
Pwd pwd,
- DataType dataType,
- RawBuffer raw = RawBuffer()) :
- Key(backendId, scheme, std::move(id), std::move(pwd)), m_type(dataType)
- {
- m_raw = std::move(raw);
- }
+ DataType dataType) :
+ Key(backendId, scheme, std::move(id), std::move(pwd)), m_type(dataType) {}
+ RawBuffer getBinary() const override;
RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message) override;
int verify(const CryptoAlgorithm &alg, const RawBuffer &message,
const RawBuffer &sign) override;
RawBuffer tag;
unpack(token.data, pass, scheme, id, iv, tag);
- if (token.dataType.isKeyPrivate())
+ if (token.dataType.isKeyPrivate() || token.dataType.isKeyPublic())
return make<AKey>(scheme, std::move(id), Pwd(pass, iv, tag), token.dataType);
if (token.dataType.isSymmetricKey())
auto pwd = Pwd(pass, iv, tag);
RawBuffer raw = Internals::getData(id, pwd);
- if (token.dataType.isKeyPublic())
- return make<AKey>(scheme, std::move(id), std::move(pwd), token.dataType, std::move(raw));
-
if (token.dataType.isBinaryData())
return make<BData>(scheme, std::move(id), std::move(pwd), std::move(raw));