rippled
Loading...
Searching...
No Matches
KeyType.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2015 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_KEYTYPE_H_INCLUDED
21#define RIPPLE_PROTOCOL_KEYTYPE_H_INCLUDED
22
23#include <optional>
24#include <string>
25
26namespace ripple {
27
28enum class KeyType {
29 secp256k1 = 0,
30 ed25519 = 1,
31};
32
35{
36 if (s == "secp256k1")
37 return KeyType::secp256k1;
38
39 if (s == "ed25519")
40 return KeyType::ed25519;
41
42 return {};
43}
44
45inline char const*
47{
48 if (type == KeyType::secp256k1)
49 return "secp256k1";
50
51 if (type == KeyType::ed25519)
52 return "ed25519";
53
54 return "INVALID";
55}
56
57template <class Stream>
58inline Stream&
59operator<<(Stream& s, KeyType type)
60{
61 return s << to_string(type);
62}
63
64} // namespace ripple
65
66#endif
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::optional< KeyType > keyTypeFromString(std::string const &s)
Definition KeyType.h:34
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition base_uint.h:647
KeyType
Definition KeyType.h:28
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630