1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "services/network/trust_tokens/types.h"
6 
7 #include "base/time/time.h"
8 #include "base/util/values/values_util.h"
9 
10 namespace network {
11 namespace internal {
12 
StringToTime(base::StringPiece my_string)13 base::Optional<base::Time> StringToTime(base::StringPiece my_string) {
14   return util::ValueToTime(base::Value(my_string));
15 }
16 
TimeToString(base::Time my_time)17 std::string TimeToString(base::Time my_time) {
18   return util::TimeToValue(my_time).GetString();
19 }
20 
TrustTokenOperationTypeToString(mojom::TrustTokenOperationType type)21 base::StringPiece TrustTokenOperationTypeToString(
22     mojom::TrustTokenOperationType type) {
23   // WARNING: These values are used to construct histogram names. When making
24   // changes, please make sure that the Trust Tokens-related histograms
25   // ("Net.TrustTokens.*") reflect the changes.
26   switch (type) {
27     case mojom::TrustTokenOperationType::kIssuance:
28       return "Issuance";
29     case mojom::TrustTokenOperationType::kRedemption:
30       return "Redemption";
31     case mojom::TrustTokenOperationType::kSigning:
32       return "Signing";
33   }
34 }
35 
ProtocolVersionToString(mojom::TrustTokenProtocolVersion my_version)36 std::string ProtocolVersionToString(
37     mojom::TrustTokenProtocolVersion my_version) {
38   switch (my_version) {
39     case mojom::TrustTokenProtocolVersion::kTrustTokenV2Pmb:
40       return "TrustTokenV2PMB";
41     case mojom::TrustTokenProtocolVersion::kTrustTokenV2Voprf:
42       return "TrustTokenV2VOPRF";
43   }
44 }
45 
46 }  // namespace internal
47 }  // namespace network
48