-
Notifications
You must be signed in to change notification settings - Fork 969
/
SignerKey.cpp
101 lines (90 loc) · 2.47 KB
/
SignerKey.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2016 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "crypto/SignerKey.h"
#include "crypto/StrKey.h"
#include "xdr/Stellar-types.h"
#include <sodium/crypto_sign.h>
namespace stellar
{
std::string
KeyFunctions<SignerKey>::getKeyTypeName()
{
return "signer key";
}
bool
KeyFunctions<SignerKey>::getKeyVersionIsSupported(strKey::StrKeyVersionByte keyVersion)
{
switch (keyVersion)
{
case strKey::STRKEY_PUBKEY_ED25519:
return true;
case strKey::STRKEY_HASH_TX:
return true;
case strKey::STRKEY_HASH_X:
return true;
default:
return false;
}
}
typename KeyFunctions<SignerKey>::getKeyTypeEnum::type
KeyFunctions<SignerKey>::toKeyType(strKey::StrKeyVersionByte keyVersion)
{
switch (keyVersion)
{
case strKey::STRKEY_PUBKEY_ED25519:
return SignerKeyType::SIGNER_KEY_TYPE_ED25519;
case strKey::STRKEY_HASH_TX:
return SignerKeyType::SIGNER_KEY_TYPE_HASH_TX;
case strKey::STRKEY_HASH_X:
return SignerKeyType::SIGNER_KEY_TYPE_HASH_X;
default:
throw std::invalid_argument("invalid signer key type");
}
}
strKey::StrKeyVersionByte
KeyFunctions<SignerKey>::toKeyVersion(SignerKeyType keyType)
{
switch (keyType)
{
case SignerKeyType::SIGNER_KEY_TYPE_ED25519:
return strKey::STRKEY_PUBKEY_ED25519;
case SignerKeyType::SIGNER_KEY_TYPE_HASH_TX:
return strKey::STRKEY_HASH_TX;
case SignerKeyType::SIGNER_KEY_TYPE_HASH_X:
return strKey::STRKEY_HASH_X;
default:
throw std::invalid_argument("invalid signer key type");
}
}
uint256 &
KeyFunctions<SignerKey>::getKeyValue(SignerKey &key)
{
switch (key.type())
{
case SIGNER_KEY_TYPE_ED25519:
return key.ed25519();
case SIGNER_KEY_TYPE_HASH_TX:
return key.hashTx();
case SIGNER_KEY_TYPE_HASH_X:
return key.hashX();
default:
throw std::invalid_argument("invalid signer key type");
}
}
uint256 const&
KeyFunctions<SignerKey>::getKeyValue(SignerKey const &key)
{
switch (key.type())
{
case SIGNER_KEY_TYPE_ED25519:
return key.ed25519();
case SIGNER_KEY_TYPE_HASH_TX:
return key.hashTx();
case SIGNER_KEY_TYPE_HASH_X:
return key.hashX();
default:
throw std::invalid_argument("invalid signer key type");
}
}
}