xref: /aosp_15_r20/external/tink/cc/subtle/common_enums.cc (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 #include "tink/subtle/common_enums.h"
18 
19 #include <string>
20 
21 #include "absl/strings/str_cat.h"
22 
23 namespace crypto {
24 namespace tink {
25 namespace subtle {
26 
EnumToString(EllipticCurveType type)27 std::string EnumToString(EllipticCurveType type) {
28   switch (type) {
29   case EllipticCurveType::NIST_P256:
30     return "NIST_P256";
31   case EllipticCurveType::NIST_P384:
32     return "NIST_P384";
33   case EllipticCurveType::NIST_P521:
34     return "NIST_P521";
35   case EllipticCurveType::CURVE25519:
36     return "CURVE25519";
37   case EllipticCurveType::UNKNOWN_CURVE:
38     return "UNKNOWN_CURVE";
39   default:
40     return absl::StrCat("UNKNOWN_CURVE: ", type);
41   }
42 }
43 
EnumToString(EcPointFormat format)44 std::string EnumToString(EcPointFormat format) {
45   switch (format) {
46   case EcPointFormat::UNCOMPRESSED:
47     return "UNCOMPRESSED";
48   case EcPointFormat::COMPRESSED:
49     return "COMPRESSED";
50   case EcPointFormat::DO_NOT_USE_CRUNCHY_UNCOMPRESSED:
51     return "DO_NOT_USE_CRUNCHY_UNCOMPRESSED";
52   case EcPointFormat::UNKNOWN_FORMAT:
53     return "UNKNOWN_FORMAT";
54   default:
55     return absl::StrCat("UNKNOWN_FORMAT: ", format);
56   }
57 }
58 
EnumToString(HashType type)59 std::string EnumToString(HashType type) {
60   switch (type) {
61   case HashType::SHA1:
62     return "SHA1";
63   case HashType::SHA224:
64     return "SHA224";
65   case HashType::SHA256:
66     return "SHA256";
67   case HashType::SHA384:
68     return "SHA384";
69   case HashType::SHA512:
70     return "SHA512";
71   case HashType::UNKNOWN_HASH:
72     return "UNKNOWN_HASH";
73   default:
74     return absl::StrCat("UNKNOWN_HASH: ", type);
75   }
76 }
77 
78 }  // namespace subtle
79 }  // namespace tink
80 }  // namespace crypto
81