Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. 2018 All Rights Reserved.
3 : * http://soramitsu.co.jp
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #ifndef IROHA_CRYPTO_MODEL_SIGNER_HPP_
19 : #define IROHA_CRYPTO_MODEL_SIGNER_HPP_
20 :
21 : #include "cryptography/crypto_provider/crypto_signer.hpp"
22 :
23 : namespace shared_model {
24 :
25 : namespace interface {
26 : class Block;
27 : class Query;
28 : class Transaction;
29 : }
30 :
31 : namespace crypto {
32 : template <typename Algorithm = CryptoSigner<>>
33 : class CryptoModelSigner {
34 : public:
35 : explicit CryptoModelSigner(const shared_model::crypto::Keypair &keypair);
36 :
37 : virtual ~CryptoModelSigner() = default;
38 :
39 : template <typename T>
40 : void sign(T &signable) const noexcept {
41 710 : auto signedBlob = Algorithm::sign(signable.payload(), keypair_);
42 710 : signable.addSignature(signedBlob, keypair_.publicKey());
43 710 : }
44 :
45 : private:
46 : shared_model::crypto::Keypair keypair_;
47 : };
48 :
49 : template <typename Algorithm>
50 : CryptoModelSigner<Algorithm>::CryptoModelSigner(
51 : const shared_model::crypto::Keypair &keypair)
52 11 : : keypair_(keypair) {}
53 :
54 : } // namespace crypto
55 : } // namespace shared_model
56 :
57 : #endif // IROHA_CRYPTO_MODEL_SIGNER_HPP_
|