virgil-crypto 2.3.0 → 3.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.gitmodules +0 -0
- data/.travis.yml +13 -0
- data/Gemfile +0 -0
- data/README.md +113 -9
- data/Rakefile +0 -0
- data/ext/native/src/.clang-format +37 -0
- data/ext/native/src/.gitignore +3 -0
- data/ext/native/src/.travis.yml +2 -1
- data/ext/native/src/CMakeLists.txt +66 -63
- data/ext/native/src/ChangeLog +114 -2
- data/ext/native/src/Dockerfile_Golang +29 -8
- data/ext/native/src/Jenkinsfile +61 -50
- data/ext/native/src/LICENSE +0 -0
- data/ext/native/src/README.md +137 -167
- data/ext/native/src/VERSION +1 -1
- data/ext/native/src/benchmark.md +140 -0
- data/ext/native/src/benchmark/CMakeLists.txt +0 -0
- data/ext/native/src/benchmark/benchmark_cipher.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_hash.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_keys.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_pythia.cxx +61 -0
- data/ext/native/src/benchmark/benchmark_random.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_signer.cxx +0 -0
- data/ext/native/src/ci/install-dependencies.sh +8 -12
- data/ext/native/src/ci/publish-docs.sh +107 -22
- data/ext/native/src/ci/travis-deployment-key.enc +0 -0
- data/ext/native/src/cmake/TransitiveArgs.cmake +78 -0
- data/ext/native/src/cmake/TransitiveToolchainArgs.cmake +105 -0
- data/ext/native/src/cmake/add_mono_metadata.cmake +103 -0
- data/ext/native/src/cmake/apple.cmake +56 -11
- data/ext/native/src/cmake/aux_source_directory_to_file.cmake +0 -0
- data/ext/native/src/cmake/check_pointer_size.cmake +0 -0
- data/ext/native/src/cmake/copy_all_files.cmake +0 -0
- data/ext/native/src/cmake/file_regex_replace.cmake +0 -0
- data/ext/native/src/cmake/find_host_utils.cmake +0 -0
- data/ext/native/src/cmake/uppercase_first_char.cmake +0 -0
- data/ext/native/src/cmake/uppercase_namespaces.cmake +3 -0
- data/ext/native/src/cmake/virgil_depends.cmake +0 -0
- data/ext/native/src/cmake/virgil_depends_local.cmake +2 -0
- data/ext/native/src/docs/.gitignore +0 -0
- data/ext/native/src/lib/CMakeLists.txt +59 -1
- data/ext/native/src/lib/Doxyfile.in +1 -1
- data/ext/native/src/lib/Info.plist.in +0 -0
- data/ext/native/src/lib/cmake/config.cmake.in +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilByteArrayUtils.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilChunkCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCipherBase.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilContentInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCrypto.h +13 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCryptoError.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCustomParams.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilKeyPair.h +30 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilSignerBase.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilStreamCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilStreamSigner.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilTinyCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilVersion.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilAsymmetricCipher.h +17 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilHKDF.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilPBKDF.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilSystemCryptoError.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContent.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContentInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEncryptedContent.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEnvelopedData.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSKeyTransRecipient.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSPasswordRecipient.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFS.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSEncryptedMessage.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPrivateInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPublicInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPrivateKey.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPublicKey.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPrivateInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPublicInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSSession.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationDH.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationHash.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationKDF.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationRandom.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythia.h +181 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaBlindResult.h +89 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaContext.h +72 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaError.h +161 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaProveResult.h +89 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformResult.h +91 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformationKeyPair.h +87 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/virgil_pythia_c.h +203 -0
- data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSink.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSource.h +0 -0
- data/ext/native/src/lib/mainpage.dox +6 -0
- data/ext/native/src/lib/module.modulemap +7 -0
- data/ext/native/src/lib/src/VirgilAsn1Alg.cxx +0 -0
- data/ext/native/src/lib/src/VirgilAsn1Alg.h +0 -0
- data/ext/native/src/lib/src/VirgilAsn1Compatible.cxx +0 -0
- data/ext/native/src/lib/src/VirgilAsymmetricCipher.cxx +82 -0
- data/ext/native/src/lib/src/VirgilByteArrayUtils.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSContent.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSContentInfo.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSEncryptedContent.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSEnvelopedData.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSKeyTransRecipient.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSPasswordRecipient.cxx +0 -0
- data/ext/native/src/lib/src/VirgilChunkCipher.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCipherBase.cxx +0 -0
- data/ext/native/src/lib/src/VirgilConfig.cxx +51 -0
- data/ext/native/src/lib/src/VirgilConfig.h.in +43 -1
- data/ext/native/src/lib/src/VirgilContentInfo.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCryptoError.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCustomParams.cxx +0 -0
- data/ext/native/src/lib/src/VirgilDataSink.cxx +0 -0
- data/ext/native/src/lib/src/VirgilHKDF.cxx +0 -0
- data/ext/native/src/lib/src/VirgilKeyPair.cxx +19 -0
- data/ext/native/src/lib/src/VirgilOID.h +0 -0
- data/ext/native/src/lib/src/VirgilPBKDF.cxx +0 -0
- data/ext/native/src/lib/src/VirgilSignerBase.cxx +0 -0
- data/ext/native/src/lib/src/VirgilStreamCipher.cxx +0 -0
- data/ext/native/src/lib/src/VirgilStreamSigner.cxx +0 -0
- data/ext/native/src/lib/src/VirgilSystemCryptoError.cxx +0 -0
- data/ext/native/src/lib/src/VirgilTagFilter.cxx +0 -0
- data/ext/native/src/lib/src/VirgilTagFilter.h +0 -0
- data/ext/native/src/lib/src/VirgilTinyCipher.cxx +0 -0
- data/ext/native/src/lib/src/VirgilVersion.cxx.in +0 -0
- data/ext/native/src/lib/src/mbedtls_context.h +0 -0
- data/ext/native/src/lib/src/mbedtls_context_policy_spec.h +0 -0
- data/ext/native/src/lib/src/mbedtls_type_utils.h +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFS.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSEncryptedMessage.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPrivateInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPublicInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSPrivateKey.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSPublicKey.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSResponderPrivateInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSResponderPublicInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSSession.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationCipher.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationDH.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationHash.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationKDF.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationRandom.cxx +0 -0
- data/ext/native/src/lib/src/pythia/VirgilPythia.cxx +202 -0
- data/ext/native/src/lib/src/pythia/VirgilPythiaContext.cxx +116 -0
- data/ext/native/src/lib/src/pythia/VirgilPythiaError.cxx +58 -0
- data/ext/native/src/lib/src/pythia/virgil_pythia_c.cxx +129 -0
- data/ext/native/src/lib/src/stream/VirgilBytesDataSink.cxx +0 -0
- data/ext/native/src/lib/src/stream/VirgilBytesDataSource.cxx +0 -0
- data/ext/native/src/lib/src/utils.h +3 -2
- data/ext/native/src/libs_ext/mbedtls/configs/config.h +0 -0
- data/ext/native/src/libs_ext/mbedtls/configs/config_desktop.h +0 -0
- data/ext/native/src/libs_ext/mbedtls/mbedtls.cmake +0 -0
- data/ext/native/src/{cmake/cmake_args.cmake → libs_ext/pythia/pythia.cmake} +24 -28
- data/ext/native/src/libs_ext/rapidjson/rapidjson.cmake +0 -0
- data/ext/native/src/libs_ext/tinyformat/cmake/config.cmake.in +0 -0
- data/ext/native/src/libs_ext/tinyformat/tinyformat.cmake +0 -0
- data/ext/native/src/migration-2.0.md +0 -0
- data/ext/native/src/tests/CMakeLists.txt +0 -0
- data/ext/native/src/tests/catch.hpp +0 -0
- data/ext/native/src/tests/data/test_data_pfs_with_otc.json +0 -0
- data/ext/native/src/tests/data/test_data_pfs_without_otc.json +0 -0
- data/ext/native/src/tests/deterministic_keys.h +293 -0
- data/ext/native/src/tests/rsa_keys.h +229 -123
- data/ext/native/src/tests/test_asn1_writer.cxx +0 -0
- data/ext/native/src/tests/test_asymmetric_cipher.cxx +65 -0
- data/ext/native/src/tests/test_base64.cxx +0 -0
- data/ext/native/src/tests/test_byte_array_utils.cxx +0 -0
- data/ext/native/src/tests/test_chunk_cipher.cxx +0 -0
- data/ext/native/src/tests/test_cipher.cxx +8 -4
- data/ext/native/src/tests/test_cipher_base.cxx +0 -0
- data/ext/native/src/tests/test_contract_copy_move.cxx +4 -1
- data/ext/native/src/tests/test_data_pfs.h +0 -0
- data/ext/native/src/tests/test_hash.cxx +0 -0
- data/ext/native/src/tests/test_hkdf.cxx +0 -0
- data/ext/native/src/tests/test_key_pair.cxx +65 -3
- data/ext/native/src/tests/test_pbe.cxx +0 -0
- data/ext/native/src/tests/test_pbkdf.cxx +0 -0
- data/ext/native/src/tests/test_pfs.cxx +0 -0
- data/ext/native/src/tests/test_pythia.cxx +157 -0
- data/ext/native/src/tests/test_random.cxx +0 -0
- data/ext/native/src/tests/test_runner.cxx +0 -0
- data/ext/native/src/tests/test_signer.cxx +0 -0
- data/ext/native/src/tests/test_stream_cipher.cxx +0 -0
- data/ext/native/src/tests/test_stream_data_source.cxx +0 -0
- data/ext/native/src/tests/test_symmetric_cipher.cxx +0 -0
- data/ext/native/src/tests/test_tag_filter.cxx +0 -0
- data/ext/native/src/tests/test_tiny_cipher.cxx +0 -0
- data/ext/native/src/utils/build.bat +0 -0
- data/ext/native/src/utils/build.sh +238 -68
- data/ext/native/src/utils/zip.vbs +0 -0
- data/ext/native/src/virgil-crypto.sublime-project +15 -0
- data/ext/native/src/wrappers/asmjs/CMakeLists.txt +0 -8
- data/ext/native/src/wrappers/emsdk/CMakeLists.txt +2 -2
- data/ext/native/src/wrappers/emsdk/error.js +0 -0
- data/ext/native/src/wrappers/emsdk/example.html +152 -31
- data/ext/native/src/wrappers/emsdk/helpers.js +140 -135
- data/ext/native/src/wrappers/emsdk/patch_embind.pl +0 -0
- data/ext/native/src/wrappers/emsdk/wrapper.cxx +55 -0
- data/ext/native/src/wrappers/go/CMakeLists.txt +6 -5
- data/ext/native/src/wrappers/java/CMakeLists.txt +27 -4
- data/ext/native/src/wrappers/java/src/JniLoader.java +167 -0
- data/ext/native/src/wrappers/java/src/VirgilStreamDataSink.java +0 -0
- data/ext/native/src/wrappers/java/src/VirgilStreamDataSource.java +0 -0
- data/ext/native/src/wrappers/net/CMakeLists.txt +41 -8
- data/ext/native/src/wrappers/net/cmake/UseCSharp.cmake +5 -5
- data/ext/native/src/wrappers/net/src/VirgilStreamDataSink.cs +0 -0
- data/ext/native/src/wrappers/net/src/VirgilStreamDataSource.cs +0 -0
- data/ext/native/src/wrappers/nodejs/checksum.txt +66 -0
- data/ext/native/src/wrappers/php/CMakeLists.txt +2 -5
- data/ext/native/src/wrappers/php/tests/CMakeLists.txt +6 -0
- data/ext/native/src/wrappers/php/tests/VirgilChunkCipher_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilCustomParams_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilKDF_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilPBE_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilPBKDF_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilPythia_Test.php.in +87 -0
- data/ext/native/src/wrappers/php/tests/VirgilStreamCipher_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilStreamSigner_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilVersion_Test.php.in +0 -0
- data/ext/native/src/wrappers/python/CMakeLists.txt +4 -1
- data/ext/native/src/wrappers/ruby/CMakeLists.txt +4 -1
- data/ext/native/src/wrappers/swig/common.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/FixedArray.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/VirgilByteArray.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/common.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/csharphead.swg.in +0 -0
- data/ext/native/src/wrappers/swig/go/common.i.in +7 -0
- data/ext/native/src/wrappers/swig/java/VirgilByteArray.i +0 -0
- data/ext/native/src/wrappers/swig/java/common.i +6 -0
- data/ext/native/src/wrappers/swig/php/common.i +0 -0
- data/ext/native/src/wrappers/swig/php/php7/VirgilByteArray.i +0 -0
- data/ext/native/src/wrappers/swig/util.i +0 -0
- data/ext/native/src/wrappers/swig/wrapper.i.in +18 -7
- data/ext/native/src/wrappers/webasm/CMakeLists.txt +0 -8
- data/ext/rakefile.rb +77 -56
- data/lib/virgil/crypto.rb +53 -9
- data/lib/virgil/crypto/access_token_signer.rb +79 -0
- data/lib/virgil/crypto/bytes.rb +81 -17
- data/lib/virgil/crypto/card_crypto.rb +115 -0
- data/lib/virgil/crypto/crypto_exception.rb +40 -0
- data/lib/virgil/crypto/hash_algorithm.rb +82 -0
- data/lib/virgil/crypto/key_pair.rb +41 -0
- data/lib/virgil/crypto/key_pair_type.rb +98 -0
- data/lib/virgil/crypto/private_key.rb +40 -0
- data/lib/virgil/crypto/private_key_exporter.rb +67 -0
- data/lib/virgil/crypto/public_key.rb +40 -0
- data/lib/virgil/crypto/{virgil_stream_data_sink.rb → stream_data_sink.rb} +12 -12
- data/lib/virgil/crypto/{virgil_stream_data_source.rb → stream_data_source.rb} +12 -12
- data/lib/virgil/crypto/validation.rb +59 -0
- data/lib/virgil/crypto/version.rb +35 -1
- data/lib/virgil/crypto/virgil_crypto.rb +595 -0
- data/lib/virgil/native_crypto.rb +80 -60
- data/lib/virgil/os.rb +40 -6
- data/secrets.tar.enc +0 -0
- data/virgil-crypto.gemspec +6 -7
- metadata +62 -12
- data/ext/native/src/cmake/android.toolchain.cmake +0 -1697
data/lib/virgil/crypto.rb
CHANGED
@@ -1,10 +1,54 @@
|
|
1
|
+
# Copyright (C) 2015-2019 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, bytes, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
1
35
|
require "virgil/crypto/version"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
36
|
+
require "virgil/crypto/virgil_crypto_ruby.bundle"
|
37
|
+
Virgil::Crypto::Core = Virgil_crypto_ruby
|
38
|
+
require "virgil/crypto/stream_data_sink"
|
39
|
+
require "virgil/crypto/stream_data_source"
|
40
|
+
require "virgil/crypto/access_token_signer"
|
41
|
+
require "virgil/crypto/private_key_exporter"
|
42
|
+
require "virgil/crypto/bytes"
|
43
|
+
require "virgil/crypto/card_crypto"
|
44
|
+
require "virgil/crypto/crypto_exception"
|
45
|
+
require "virgil/crypto/hash_algorithm"
|
46
|
+
require "virgil/crypto/key_pair"
|
47
|
+
require "virgil/crypto/key_pair_type"
|
48
|
+
require "virgil/crypto/private_key"
|
49
|
+
require "virgil/crypto/public_key"
|
50
|
+
require "virgil/crypto/validation"
|
51
|
+
require "virgil/crypto/virgil_crypto"
|
52
|
+
|
53
|
+
|
54
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright (C) 2015-2019 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, bytes, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module Crypto
|
37
|
+
# Provides a cryptographic operations in applications, such as signature generation
|
38
|
+
# and verification in an access token.
|
39
|
+
class VirgilAccessTokenSigner
|
40
|
+
|
41
|
+
|
42
|
+
# Represents used signature algorithm.
|
43
|
+
attr_reader :algorithm
|
44
|
+
|
45
|
+
# Initializes a new instance of the [VirgilAccessTokenSigner] class.
|
46
|
+
def initialize
|
47
|
+
@virgil_crypto = VirgilCrypto.new
|
48
|
+
@algorithm = 'VEDS512'
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generates the digital signature for the specified token_bytes
|
52
|
+
# using the specified [VirgilPrivateKey]
|
53
|
+
# @param token_bytes [Bytes] The material representation bytes of access token
|
54
|
+
# for which to compute the signature.
|
55
|
+
# @param private_key [VirgilPrivateKey] The digital signature for the material representation
|
56
|
+
# bytes of access token.
|
57
|
+
# @return The digital signature for the material representation bytes of access token.
|
58
|
+
def generate_token_signature(token_bytes, private_key)
|
59
|
+
@virgil_crypto.generate_signature(token_bytes, private_key)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Verifies that a digital signature is valid by checking the signature,
|
63
|
+
# provided public_key and token_bytes
|
64
|
+
# @param signature [Bytes] The digital signature for the token_bytes
|
65
|
+
# @param token_bytes [Bytes] The material representation bytes of access token
|
66
|
+
# for which the signature has been generated.
|
67
|
+
# @param public_key [VirgilPublicKey] public
|
68
|
+
# key for verification.
|
69
|
+
# @return [Boolean] True if signature is valid, False otherwise.
|
70
|
+
def verify_token_signature(signature, token_bytes, public_key)
|
71
|
+
@virgil_crypto.verify_signature(signature, token_bytes, public_key)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
attr_reader :virgil_crypto
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/virgil/crypto/bytes.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C)
|
1
|
+
# Copyright (C) 2015-2019 Virgil Security Inc.
|
2
2
|
#
|
3
3
|
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
4
|
#
|
@@ -8,17 +8,17 @@
|
|
8
8
|
# modification, are permitted provided that the following conditions are
|
9
9
|
# met:
|
10
10
|
#
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
13
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
18
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
22
|
#
|
23
23
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
24
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
@@ -26,36 +26,100 @@
|
|
26
26
|
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
27
|
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
28
|
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
-
# SERVICES; LOSS OF USE,
|
29
|
+
# SERVICES; LOSS OF USE, bytes, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
30
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
31
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
32
|
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
33
|
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
34
35
|
require 'base64'
|
35
36
|
require 'json'
|
36
37
|
|
37
38
|
module Virgil
|
38
39
|
module Crypto
|
39
40
|
class Bytes < Array
|
40
|
-
|
41
|
-
|
41
|
+
# Initializes a new array of bytes from specified string, which encodes binary data.
|
42
|
+
# @param str [String] String to decode.
|
43
|
+
# @param encoding [VirgilStringEncoding] The character encoding of string.
|
44
|
+
# @raise [ArgumentError] if encoding is undefined
|
45
|
+
def self.from_string(str, encoding = VirgilStringEncoding::UTF8)
|
46
|
+
case encoding
|
47
|
+
when VirgilStringEncoding::BASE64
|
48
|
+
from_base64(str)
|
49
|
+
when VirgilStringEncoding::HEX
|
50
|
+
from_hex(str)
|
51
|
+
when VirgilStringEncoding::UTF8
|
52
|
+
from_utf8(str)
|
53
|
+
else
|
54
|
+
raise ArgumentError, 'Encoding is undefined'
|
55
|
+
end
|
42
56
|
end
|
43
57
|
|
44
|
-
|
45
|
-
|
58
|
+
# Decodes the current bytes to a string according to the specified
|
59
|
+
# character encoding.
|
60
|
+
# @param encoding [VirgilStringEncoding] The character encoding to encode to.
|
61
|
+
# equivalent string representation if raw bytes in selected encoding.
|
62
|
+
# @return [String]
|
63
|
+
# @raise [ArgumentError] if encoding is undefined
|
64
|
+
def to_string(encoding = VirgilStringEncoding::UTF8)
|
65
|
+
case encoding
|
66
|
+
when VirgilStringEncoding::BASE64
|
67
|
+
to_base64
|
68
|
+
when VirgilStringEncoding::HEX
|
69
|
+
to_hex
|
70
|
+
when VirgilStringEncoding::UTF8
|
71
|
+
to_s
|
72
|
+
else
|
73
|
+
raise ArgumentError, 'Encoding is undefined'
|
74
|
+
end
|
46
75
|
end
|
47
76
|
|
77
|
+
# Converts all the bytes to its equivalent string representation in utf8.
|
48
78
|
def to_s
|
49
79
|
pack('c*')
|
50
80
|
end
|
51
81
|
|
52
|
-
|
53
|
-
|
82
|
+
# Initializes a new array of bytes from specified string,
|
83
|
+
# which encodes binary data as base-64 digits.
|
84
|
+
def self.from_base64(str)
|
85
|
+
new(Base64.decode64(str).bytes)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Initializes a new array of bytes from specified string,
|
89
|
+
# which encodes binary data as utf8.
|
90
|
+
def self.from_utf8(str)
|
91
|
+
new(str.bytes)
|
54
92
|
end
|
55
93
|
|
94
|
+
# Initializes a new array of bytes from specified string,
|
95
|
+
# which encodes binary data as hexadecimal digits.
|
96
|
+
def self.from_hex(str)
|
97
|
+
new(str.scan(/../).map { |x| x.hex })
|
98
|
+
end
|
99
|
+
|
100
|
+
# Converts all the bytes to its equivalent string representation that
|
101
|
+
# is encoded with base-64 digits.
|
56
102
|
def to_base64
|
57
103
|
Base64.strict_encode64(to_s)
|
58
104
|
end
|
105
|
+
|
106
|
+
# Encodes all the bytes into a utf8 string.
|
107
|
+
def to_utf8
|
108
|
+
to_s
|
109
|
+
end
|
110
|
+
|
111
|
+
# Converts the numeric value of each element of a current array of bytes to its
|
112
|
+
# equivalent hexadecimal string representation.
|
113
|
+
def to_hex
|
114
|
+
to_s.each_byte.map { |b| b.to_s(16) }.join
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
module VirgilStringEncoding
|
120
|
+
BASE64 = 1
|
121
|
+
HEX = 2
|
122
|
+
UTF8 = 3
|
59
123
|
end
|
60
124
|
end
|
61
125
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Copyright (C) 2015-2019 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, bytes, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module Crypto
|
37
|
+
# Provides a cryptographic operations in applications, such as hashing,
|
38
|
+
# signature generation and verification, and encryption and decryption.
|
39
|
+
class VirgilCardCrypto
|
40
|
+
attr_reader :virgil_crypto
|
41
|
+
|
42
|
+
# Initializes a new instance of the [VirgilCardCrypto] class.
|
43
|
+
def initialize
|
44
|
+
@virgil_crypto = VirgilCrypto.new
|
45
|
+
end
|
46
|
+
|
47
|
+
# Imports the Public key from material representation.
|
48
|
+
# @param key_bytes [Crypto::Bytes] public key material
|
49
|
+
# representation bytes.
|
50
|
+
# @return [VirgilPublicKey] Imported public key.
|
51
|
+
# @example
|
52
|
+
# include Virgil::Crypto
|
53
|
+
# card_crypto = VirgilCardCrypto.new
|
54
|
+
# public_key = card_crypto.import_public_key(exported_public_key)
|
55
|
+
# @see #export_public_key How to get exported_public_key
|
56
|
+
def import_public_key(key_bytes)
|
57
|
+
@virgil_crypto.import_public_key(key_bytes)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Exports the Public key into material representation.
|
61
|
+
# @param public_key [VirgilPublicKey] public key for export.
|
62
|
+
# @return [Crypto::Bytes] Key material representation bytes.
|
63
|
+
# @example
|
64
|
+
# include Virgil::Crypto
|
65
|
+
# crypto = VirgilCrypto.new
|
66
|
+
# alice_keys = crypto.generate_keys
|
67
|
+
# card_crypto = VirgilCardCrypto.new
|
68
|
+
# exported_public_key = card_crypto.export_public_key(alice_keys.public_key)
|
69
|
+
def export_public_key(public_key)
|
70
|
+
@virgil_crypto.export_public_key(public_key)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Signs the specified data using Private key.
|
74
|
+
# @param bytes [Crypto::Bytes] raw data bytes for signing.
|
75
|
+
# @param private_key [VirgilPrivateKey] private key for signing.
|
76
|
+
# @return [Crypto::Bytes] Signature data.
|
77
|
+
# @example Sign the fingerprint of bytes using your private key.
|
78
|
+
# include Virgil::Crypto
|
79
|
+
# crypto = VirgilCrypto.new
|
80
|
+
# alice_keys = crypto.generate_keys()
|
81
|
+
# # The data to be signed with alice's Private key
|
82
|
+
# data = Bytes.from_string('Hello Bob, How are you?')
|
83
|
+
# card_crypto = VirgilCardCrypto.new
|
84
|
+
# signature = card_crypto.generate_signature(data, alice.private_key)
|
85
|
+
def generate_signature(bytes, private_key)
|
86
|
+
@virgil_crypto.generate_signature(bytes, private_key)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Verifies the specified signature using original data
|
90
|
+
# and signer's public key.
|
91
|
+
# @param bytes [Crypto::Bytes] original data bytes for verification.
|
92
|
+
# @param signature [Crypto::Bytes] signature bytes for verification.
|
93
|
+
# @param signer_public_key [VirgilPublicKey] signer public
|
94
|
+
# key for verification.
|
95
|
+
# @return [Boolean] True if signature is valid, False otherwise.
|
96
|
+
# @example Verify the signature of the fingerprint of
|
97
|
+
# bytes using Public key.
|
98
|
+
# include Virgil::Crypto
|
99
|
+
# card_crypto = VirgilCardCrypto.new
|
100
|
+
# public_key = crypto.import_public_key(exported_public_key)
|
101
|
+
# data = Bytes.from_string('Hello Bob, How are you?')
|
102
|
+
# is_valid = card_crypto.verify_signature(signature, data, public_key)
|
103
|
+
def verify_signature(signature, bytes, signer_public_key)
|
104
|
+
@virgil_crypto.verify_signature(signature, bytes, signer_public_key)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Calculates the fingerprint.
|
108
|
+
# @param bytes [Crypto::Bytes] original data bytes to be hashed.
|
109
|
+
# @return [Crypto::Bytes] SHA512 hash value.
|
110
|
+
def generate_SHA512(bytes)
|
111
|
+
@virgil_crypto.generate_hash(bytes)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (C) 2015-2019 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, bytes, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module Crypto
|
37
|
+
class VirgilCryptoException < StandardError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright (C) 2015-2019 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, bytes, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module Crypto
|
37
|
+
# Enumeration containing supported Algorithms
|
38
|
+
class HashAlgorithm
|
39
|
+
|
40
|
+
# Exception raised when Unknown Algorithm passed to converting method
|
41
|
+
class UnknownAlgorithmException < StandardError
|
42
|
+
def initialize(algorithm)
|
43
|
+
@algorithm = algorithm
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
"KeyPairType not found: #{@algorithm}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
MD5 = :MD5
|
53
|
+
SHA1 = :SHA1
|
54
|
+
SHA224 = :SHA224
|
55
|
+
SHA256 = :SHA256
|
56
|
+
SHA384 = :SHA384
|
57
|
+
SHA512 = :SHA512
|
58
|
+
|
59
|
+
ALGORITHMS_TO_NATIVE = {
|
60
|
+
MD5: Core::VirgilHash::Algorithm_MD5,
|
61
|
+
SHA1: Core::VirgilHash::Algorithm_SHA1,
|
62
|
+
SHA224: Core::VirgilHash::Algorithm_SHA224,
|
63
|
+
SHA256: Core::VirgilHash::Algorithm_SHA256,
|
64
|
+
SHA384: Core::VirgilHash::Algorithm_SHA384,
|
65
|
+
SHA512: Core::VirgilHash::Algorithm_SHA512
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
# Converts algorithm enum value to native value
|
70
|
+
# @param algorithm [HashAlgorithm] algorithm for conversion.
|
71
|
+
# @return [Integer] Native library algorithm id.
|
72
|
+
# @raise [UnknownAlgorithmException] if algorithm is not supported.
|
73
|
+
def self.convert_to_native(algorithm)
|
74
|
+
if ALGORITHMS_TO_NATIVE.has_key?(algorithm)
|
75
|
+
return ALGORITHMS_TO_NATIVE[algorithm]
|
76
|
+
end
|
77
|
+
|
78
|
+
raise UnknownAlgorithmException("KeyPairType not found: #{algorithm}")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|