forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
2,532 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_subdirectory(crypto) | ||
add_subdirectory(datetime) | ||
add_subdirectory(timer) | ||
add_subdirectory(dao) | ||
add_subdirectory(dao) | ||
add_subdirectory(logger) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. | ||
* http://soramitsu.co.jp | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef IROHA_COMMON_HPP | ||
#define IROHA_COMMON_HPP | ||
|
||
#include <dirent.h> | ||
#include <array> | ||
#include <cstdio> | ||
|
||
/** | ||
* This file defines common types used in iroha. | ||
* | ||
* std::string is convenient to use but it is not safe, because we can not | ||
* guarantee at compile-time fixed length of the string. | ||
* | ||
* For std::array it is possible, so we prefer it over std::string. | ||
*/ | ||
namespace iroha { | ||
|
||
/** | ||
* Base type which represents blob of fixed size. | ||
*/ | ||
template <size_t size_> | ||
class blob_t : public std::array<uint8_t, size_> { | ||
/** | ||
* Dark magic of C++, do not touch pls :) | ||
* author: @warchant | ||
*/ | ||
public: | ||
/** | ||
* In compile-time returns size of current blob. | ||
*/ | ||
constexpr static size_t size() { return size_; } | ||
|
||
/** | ||
* Converts current blob to std::string | ||
*/ | ||
std::string to_string() const noexcept { | ||
return std::string{this->begin(), this->end()}; | ||
} | ||
|
||
/** | ||
* Converts current blob to base64, represented as std::string | ||
*/ | ||
std::string to_base64() const noexcept { | ||
return base64_encode(this->data(), size_); | ||
} | ||
|
||
/** | ||
* Converts current blob to hex string. | ||
*/ | ||
std::string to_hexstring() const noexcept { | ||
std::string res(size_ * 2, 0); | ||
uint8_t front, back; | ||
auto ptr = this->data(); | ||
for (uint32_t i = 0, k = 0; i < size_; i++) { | ||
front = (uint8_t)(ptr[i] & 0xF0) >> 4; | ||
back = (uint8_t)(ptr[i] & 0xF); | ||
res[k++] = code[front]; | ||
res[k++] = code[back]; | ||
} | ||
return res; | ||
} | ||
|
||
private: | ||
static const std::string code = {'0', '1', '2', '3', '4', '5', '6', '7', | ||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; | ||
}; | ||
|
||
template <size_t size> | ||
using hash_t = blob_t<size>; | ||
|
||
// fixed-size hashes | ||
using hash224_t = hash_t<224 / 8>; | ||
using hash256_t = hash_t<256 / 8>; | ||
using hash384_t = hash_t<384 / 8>; | ||
using hash512_t = hash_t<512 / 8>; | ||
|
||
namespace ed25519 { | ||
using sig_t = blob_t<64>; // ed25519 sig is 64 bytes length | ||
using pubkey_t = blob_t<32>; | ||
using privkey_t = blob_t<64>; | ||
} | ||
|
||
// timestamps | ||
using ts64_t = uint64_t; | ||
using ts32_t = uint32_t; | ||
|
||
} // namespace iroha | ||
#endif // IROHA_COMMON_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
add_library(hash STATIC | ||
hash.cpp | ||
hash.hpp | ||
) | ||
|
||
target_link_libraries(hash PUBLIC | ||
keccak | ||
) | ||
|
||
|
||
|
||
|
||
add_library(crypto STATIC | ||
common.hpp | ||
base64.hpp | ||
hash.hpp | ||
keypair.hpp | ||
crypto.cpp | ||
crypto.hpp | ||
) | ||
|
||
target_link_libraries(crypto PUBLIC | ||
keccak | ||
ed25519 | ||
optional | ||
any | ||
) | ||
crypto.hpp | ||
ed25519_impl.cpp | ||
) | ||
target_link_libraries(crypto PUBLiC | ||
ed25519 | ||
hash | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.