#ifndef CHROMEOS_COMPONENTS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_
#define CHROMEOS_COMPONENTS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_
#include <map>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "components/account_id/account_id.h"
#include "net/cert/x509_certificate.h"
#include "net/ssl/ssl_private_key.h"
namespace chromeos {
namespace certificate_provider {
class COMPONENT_EXPORT(CERTIFICATE_PROVIDER) SignRequests {
public:
using ExtensionNameRequestIdPair = std::pair<std::string, int>;
SignRequests();
~SignRequests();
int AddRequest(const std::string& extension_id,
const scoped_refptr<net::X509Certificate>& certificate,
const std::optional<AccountId>& authenticating_user_account_id,
net::SSLPrivateKey::SignCallback callback);
std::vector<ExtensionNameRequestIdPair> FindRequestsForAuthenticatingUser(
const AccountId& authenticating_user_account_id) const;
bool RemoveRequest(const std::string& extension_id,
int request_id,
scoped_refptr<net::X509Certificate>* certificate,
net::SSLPrivateKey::SignCallback* callback);
std::vector<net::SSLPrivateKey::SignCallback> RemoveAllRequests(
const std::string& extension_id);
private:
struct Request {
Request(const scoped_refptr<net::X509Certificate>& certificate,
const std::optional<AccountId>& authenticating_user_account_id,
net::SSLPrivateKey::SignCallback callback);
Request(Request&& other);
Request& operator=(Request&&);
~Request();
scoped_refptr<net::X509Certificate> certificate;
std::optional<AccountId> authenticating_user_account_id;
net::SSLPrivateKey::SignCallback callback;
};
struct RequestsState {
RequestsState();
RequestsState(RequestsState&& other);
RequestsState& operator=(RequestsState&&);
~RequestsState();
std::map<int, Request> pending_requests;
int next_free_id = 0;
};
std::map<std::string, RequestsState> extension_to_requests_;
};
}
}
#endif