23 #include <boost/algorithm/string/case_conv.hpp> 24 #include <boost/algorithm/string.hpp> 38 string ICAP::iban(std::string _c, std::string _d)
42 auto totStr = _d + _c +
"00";
46 tot = tot * 100 +
x -
'A' + 10;
48 tot = tot * 10 + x -
'0';
49 unsigned check = (unsigned)(
u256)(98 - tot % 97);
51 out << _c << setfill(
'0') << setw(2) << check << _d;
55 std::pair<string, string> ICAP::fromIBAN(std::string _iban)
58 return std::make_pair(
string(), string());
59 boost::to_upper(_iban);
60 std::string
c = _iban.substr(0, 2);
61 std::string
d = _iban.substr(4);
62 if (iban(c, d) != _iban)
63 return std::make_pair(
string(),
string());
64 return make_pair(c, d);
72 ret = Secret::random();
78 ICAP ICAP::decoded(std::string
const& _encoded)
83 std::tie(country, data) = fromIBAN(_encoded);
85 BOOST_THROW_EXCEPTION(InvalidICAP());
86 if (data.size() == 30 || data.size() == 31)
92 else if (data.size() == 16)
95 ret.
m_asset = data.substr(0, 3);
102 BOOST_THROW_EXCEPTION(InvalidICAP());
105 BOOST_THROW_EXCEPTION(InvalidICAP());
110 std::string ICAP::encoded()
const 112 if (m_type == Direct)
114 std::string
d = toBase36<Address::size>(m_direct);
115 while (d.size() < 30)
117 return iban(
"XE", d);
119 else if (m_type == Indirect)
122 m_asset.find_first_not_of(
"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") != string::npos ||
123 m_institution.find_first_not_of(
"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") != string::npos ||
124 m_client.find_first_not_of(
"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") != string::npos ||
125 m_asset.size() != 3 ||
126 (boost::to_upper_copy(m_asset) !=
"XET" && boost::to_upper_copy(m_asset) !=
"ETH") ||
127 m_institution.size() != 4 ||
130 BOOST_THROW_EXCEPTION(InvalidICAP());
131 return iban(
"XE", m_asset + m_institution + m_client);
134 BOOST_THROW_EXCEPTION(InvalidICAP());
139 auto resolve = [&](
string const& s)
146 return abiOut<Address>(_call(_reg,
abiIn(
"addr(string)", s)));
148 if (m_asset ==
"XET")
151 bytes d =
abiIn(
"deposit(uint64)", fromBase36<8>(m_client));
152 return make_pair(a, d);
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
#define function(a, b, c, d, k, s)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
std::string m_institution
std::hash for asio::adress
bytes abiIn(std::string _id, T const &..._t)
std::vector< byte > bytes
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Address toAddress(Public const &_public)
Convert a public key to address.
Encapsulation of an ICAP address.