blob: 1a2d28879acfbd6f3e1971a753a7ca1f657e53b4 [file] [log] [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_UNEXPORTABLE_KEYS_SERVICE_ERROR_H_
#define COMPONENTS_UNEXPORTABLE_KEYS_SERVICE_ERROR_H_
#include <stdint.h>
#include "base/types/expected.h"
namespace unexportable_keys {
// Various errors returned by this component.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// LINT.IfChange(ServiceError)
enum class ServiceError : uint8_t {
// Reserved for histograms.
// kNone = 0
// crypto:: operation returned an error.
kCryptoApiFailed = 1,
// Provided key ID is unknown and doesn't correspond to any key.
kKeyNotFound = 2,
// Newly generated key is the same as the existing one (should be extremely
// rare).
kKeyCollision = 3,
// Unexportable key provider is not available on this platform.
kNoKeyProvider = 4,
// None of the requested algorithms are supported by the key provider.
kAlgorithmNotSupported = 5,
// The key object hasn't been created yet. Try again later.
kKeyNotReady = 6,
// The returned signature did not verify with the corresponding public key.
kVerifySignatureFailed = 7,
// The operation is not supported by the key provider.
kOperationNotSupported = 8,
kMaxValue = kOperationNotSupported
};
// LINT.ThenChange(
// /components/unexportable_keys/mojom/unexportable_key_service.mojom:ServiceError,
// /tools/metrics/histograms/metadata/net/enums.xml:UnexportableKeyServiceResult
// )
// Fake `ServiceError` value that can be used for metrics to signify that no
// error has occurred.
constexpr ServiceError kNoServiceErrorForMetrics = static_cast<ServiceError>(0);
// Return value for methods which perform unexportable keys operations that may
// fail. Either contains a `ServiceError` or a result value of arbitrary type.
template <class Result>
using ServiceErrorOr = base::expected<Result, ServiceError>;
} // namespace unexportable_keys
#endif // COMPONENTS_UNEXPORTABLE_KEYS_SERVICE_ERROR_H_