#pragma once

#include <vector>

#include "RsaPrivateKey.hpp"


namespace drp::util::crypto {


/**
 * Represent an RSA public key.
 */
class RsaPublicKey {
public:
    RsaPublicKey();
    explicit RsaPublicKey(const std::vector<uint8_t>& data, int padMode);

    /**
     * Encrypt data with the public key. Can only be decrypted with the corresponding private key.
     * @param plainData the plain data.
     * @return the encrypted data.
     */
    [[nodiscard]] std::vector<uint8_t> encrypt(const std::vector<std::uint8_t>& plainData) const;

    [[nodiscard]] std::vector<std::uint8_t> serialize() const;
    static RsaPublicKey deserialize(std::vector<std::uint8_t>& data);

private:
    [[nodiscard]] std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)> getOpenSslKey() const;

    int padMode {};
    std::vector<uint8_t> _data;
};


}
