cryptopp 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +14 -0
- data/Guardfile +17 -0
- data/MIT-LICENSE +1 -1
- data/Rakefile +20 -27
- data/VERSION +1 -0
- data/cryptopp.gemspec +7 -182
- data/ext/Rakefile +2 -2
- data/ext/ciphers.cpp +619 -619
- data/ext/cryptopp.cpp +220 -217
- data/ext/cryptopp_ruby_api.h +7 -7
- data/ext/defs/hashes.def +16 -0
- data/ext/defs/hmacs.def +16 -0
- data/ext/digests.cpp +635 -601
- data/ext/extconf.rb +61 -19
- data/ext/j3way.cpp +5 -5
- data/ext/j3way.h +6 -6
- data/ext/jadler32.h +6 -6
- data/ext/jaes.cpp +5 -5
- data/ext/jaes.h +6 -6
- data/ext/jarc4.cpp +5 -5
- data/ext/jarc4.h +6 -6
- data/ext/jbase.cpp +94 -94
- data/ext/jbase.h +49 -55
- data/ext/jbasiccipherinfo.h +23 -23
- data/ext/jblowfish.cpp +5 -5
- data/ext/jblowfish.h +6 -6
- data/ext/jcamellia.cpp +5 -7
- data/ext/jcamellia.h +6 -8
- data/ext/jcast128.cpp +5 -5
- data/ext/jcast128.h +6 -6
- data/ext/jcast256.cpp +5 -5
- data/ext/jcast256.h +6 -6
- data/ext/jcipher.cpp +62 -62
- data/ext/jcipher.h +24 -24
- data/ext/jcipher_t.h +383 -383
- data/ext/jconfig.h +29 -46
- data/ext/jconstants.h +120 -122
- data/ext/jcrc32.h +6 -6
- data/ext/jdes.cpp +5 -5
- data/ext/jdes.h +6 -6
- data/ext/jdes_ede2.cpp +5 -5
- data/ext/jdes_ede2.h +6 -6
- data/ext/jdes_ede3.cpp +5 -5
- data/ext/jdes_ede3.h +6 -6
- data/ext/jdes_xex3.cpp +5 -5
- data/ext/jdes_xex3.h +6 -6
- data/ext/jdiamond2.cpp +5 -5
- data/ext/jdiamond2.h +6 -6
- data/ext/jdiamond2lite.cpp +5 -5
- data/ext/jdiamond2lite.h +6 -6
- data/ext/jexception.h +5 -5
- data/ext/jgost.cpp +5 -5
- data/ext/jgost.h +6 -6
- data/ext/jhash.cpp +51 -51
- data/ext/jhash.h +22 -27
- data/ext/jhash_t.h +59 -59
- data/ext/jhaval.h +15 -15
- data/ext/jhelpers.cpp +54 -54
- data/ext/jhelpers.h +3 -3
- data/ext/jhmac.cpp +20 -20
- data/ext/jhmac.h +15 -15
- data/ext/jhmac_t.h +40 -72
- data/ext/jidea.cpp +5 -5
- data/ext/jidea.h +6 -6
- data/ext/jmarc4.cpp +5 -5
- data/ext/jmarc4.h +6 -6
- data/ext/jmars.cpp +5 -5
- data/ext/jmars.h +6 -6
- data/ext/jmd2.h +9 -9
- data/ext/jmd4.h +9 -9
- data/ext/jmd5.h +9 -9
- data/ext/jpanamacipher.cpp +7 -7
- data/ext/jpanamacipher.h +9 -9
- data/ext/jpanamahash.h +9 -9
- data/ext/jrc2.cpp +15 -15
- data/ext/jrc2.h +11 -11
- data/ext/jrc5.cpp +5 -5
- data/ext/jrc5.h +6 -6
- data/ext/jrc6.cpp +5 -5
- data/ext/jrc6.h +6 -6
- data/ext/jripemd160.h +28 -28
- data/ext/jsafer.cpp +7 -7
- data/ext/jsafer.h +9 -9
- data/ext/jseal.cpp +7 -7
- data/ext/jseal.h +9 -9
- data/ext/jserpent.cpp +5 -5
- data/ext/jserpent.h +6 -6
- data/ext/jsha.h +38 -37
- data/ext/jsha3.h +130 -0
- data/ext/jsha3_blocksizes.h +73 -0
- data/ext/jshacal2.cpp +5 -5
- data/ext/jshacal2.h +6 -6
- data/ext/jshark.cpp +5 -7
- data/ext/jshark.h +6 -8
- data/ext/jsink.cpp +57 -57
- data/ext/jsink.h +127 -123
- data/ext/jskipjack.cpp +5 -5
- data/ext/jskipjack.h +6 -6
- data/ext/jsquare.cpp +5 -5
- data/ext/jsquare.h +6 -6
- data/ext/jstream.cpp +3 -3
- data/ext/jstream.h +3 -3
- data/ext/jstream_t.h +74 -126
- data/ext/jtea.cpp +5 -5
- data/ext/jtea.h +6 -6
- data/ext/jtiger.h +9 -11
- data/ext/jtwofish.cpp +5 -5
- data/ext/jtwofish.h +6 -6
- data/ext/jwhirlpool.h +9 -11
- data/ext/utils.cpp +3 -3
- data/extras/parser_c.rb +102 -102
- data/test/ciphers_test.rb +24 -30
- data/test/data/ciphers/3desval.yml +13 -0
- data/test/data/ciphers/3wayval.yml +17 -0
- data/test/data/ciphers/arc4.yml +22 -0
- data/test/data/ciphers/blowfish.yml +9 -0
- data/test/data/ciphers/camellia.yml +21 -0
- data/test/data/ciphers/cast128v.yml +13 -0
- data/test/data/ciphers/cast256v.yml +13 -0
- data/test/data/ciphers/descert.yml +723 -0
- data/test/data/ciphers/diamond.yml +31 -0
- data/test/data/ciphers/gostval.yml +33 -0
- data/test/data/ciphers/ideaval.yml +45 -0
- data/test/data/ciphers/marsval.yml +37 -0
- data/test/data/ciphers/panamac.yml +11 -0
- data/test/data/ciphers/rc2val.yml +49 -0
- data/test/data/ciphers/rc5val.yml +26 -0
- data/test/data/ciphers/rc6val.yml +25 -0
- data/test/data/ciphers/rijndael.yml +37 -0
- data/test/data/ciphers/saferval.yml +77 -0
- data/test/data/ciphers/seal.yml +6 -0
- data/test/data/ciphers/serpentv.yml +37 -0
- data/test/data/ciphers/shacal2.yml +21 -0
- data/test/data/ciphers/sharkval.yml +29 -0
- data/test/data/ciphers/skipjack.yml +5 -0
- data/test/data/ciphers/squareva.yml +33 -0
- data/test/data/ciphers/twofishv.yml +37 -0
- data/test/data/digests/adler32.yml +19 -0
- data/test/data/digests/crc32.yml +25 -0
- data/test/data/digests/haval.yml +7 -0
- data/test/data/digests/havalcer.yml +1 -0
- data/test/data/digests/md2.yml +22 -0
- data/test/data/digests/md4.yml +22 -0
- data/test/data/digests/md5.yml +22 -0
- data/test/data/digests/panamah.yml +13 -0
- data/test/data/digests/ripemd.yml +97 -0
- data/test/data/digests/sha.yml +25 -0
- data/test/data/digests/sha3.yml +23 -0
- data/test/data/digests/tiger.yml +30 -0
- data/test/data/digests/whirlpool.yml +25 -0
- data/test/data/hmacs/hmac.yml +14 -0
- data/test/digests_test.rb +17 -23
- data/test/hmacs_test.rb +25 -31
- data/test/test_helper.rb +31 -37
- metadata +70 -82
- data/test/data/ciphers/3desval.dat +0 -7
- data/test/data/ciphers/3wayval.dat +0 -6
- data/test/data/ciphers/arc4.dat +0 -8
- data/test/data/ciphers/blowfish.dat +0 -5
- data/test/data/ciphers/camellia.dat +0 -7
- data/test/data/ciphers/cast128v.dat +0 -5
- data/test/data/ciphers/cast256v.dat +0 -5
- data/test/data/ciphers/descert.dat +0 -198
- data/test/data/ciphers/diamond.dat +0 -9
- data/test/data/ciphers/gostval.dat +0 -10
- data/test/data/ciphers/ideaval.dat +0 -13
- data/test/data/ciphers/marsval.dat +0 -11
- data/test/data/ciphers/panamac.dat +0 -7
- data/test/data/ciphers/rc2val.dat +0 -10
- data/test/data/ciphers/rc5val.dat +0 -7
- data/test/data/ciphers/rc6val.dat +0 -8
- data/test/data/ciphers/rijndael.dat +0 -11
- data/test/data/ciphers/saferval.dat +0 -27
- data/test/data/ciphers/seal.dat +0 -3
- data/test/data/ciphers/serpentv.dat +0 -11
- data/test/data/ciphers/shacal2.dat +0 -7
- data/test/data/ciphers/sharkval.dat +0 -9
- data/test/data/ciphers/skipjack.dat +0 -3
- data/test/data/ciphers/squareva.dat +0 -10
- data/test/data/ciphers/twofishv.dat +0 -11
- data/test/data/digests/adler32.dat +0 -8
- data/test/data/digests/crc32.dat +0 -10
- data/test/data/digests/haval.dat +0 -4
- data/test/data/digests/havalcer.dat +0 -23
- data/test/data/digests/md2.dat +0 -9
- data/test/data/digests/md4.dat +0 -9
- data/test/data/digests/md5.dat +0 -9
- data/test/data/digests/panamah.dat +0 -8
- data/test/data/digests/ripemd.dat +0 -43
- data/test/data/digests/sha.dat +0 -19
- data/test/data/digests/tiger.dat +0 -11
- data/test/data/digests/whirlpool.dat +0 -13
- data/test/data/hmacs/hmac.dat +0 -6
@@ -0,0 +1,73 @@
|
|
1
|
+
// sha3.h - written and placed in the public domain by Wei Dai
|
2
|
+
//
|
3
|
+
// This is a patched version of sha3.h that includes definitions for the
|
4
|
+
// BLOCKSIZE constants that appear to be missing from the header file.
|
5
|
+
// See http://sourceforge.net/apps/trac/cryptopp/ticket/31 for details.
|
6
|
+
|
7
|
+
#ifndef CRYPTOPP_JSHA3_BLOCKSIZES_H
|
8
|
+
#define CRYPTOPP_JSHA3_BLOCKSIZES_H
|
9
|
+
|
10
|
+
#include "cryptlib.h"
|
11
|
+
#include "secblock.h"
|
12
|
+
|
13
|
+
NAMESPACE_BEGIN(CryptoPP)
|
14
|
+
|
15
|
+
/// <a href="http://en.wikipedia.org/wiki/SHA-3">SHA-3</a>
|
16
|
+
class SHA3 : public HashTransformation
|
17
|
+
{
|
18
|
+
public:
|
19
|
+
SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
|
20
|
+
unsigned int DigestSize() const {return m_digestSize;}
|
21
|
+
std::string AlgorithmName() const {return "SHA-3-" + IntToString(m_digestSize*8);}
|
22
|
+
unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
|
23
|
+
|
24
|
+
void Update(const byte *input, size_t length);
|
25
|
+
void Restart();
|
26
|
+
void TruncatedFinal(byte *hash, size_t size);
|
27
|
+
|
28
|
+
protected:
|
29
|
+
inline unsigned int r() const {return 200 - 2 * m_digestSize;}
|
30
|
+
|
31
|
+
FixedSizeSecBlock<word64, 25> m_state;
|
32
|
+
unsigned int m_digestSize, m_counter;
|
33
|
+
};
|
34
|
+
|
35
|
+
class SHA3_224 : public SHA3
|
36
|
+
{
|
37
|
+
public:
|
38
|
+
CRYPTOPP_CONSTANT(DIGESTSIZE = 28)
|
39
|
+
CRYPTOPP_CONSTANT(BLOCKSIZE = 144)
|
40
|
+
SHA3_224() : SHA3(DIGESTSIZE) {}
|
41
|
+
static const char * StaticAlgorithmName() {return "SHA-3-224";}
|
42
|
+
};
|
43
|
+
|
44
|
+
class SHA3_256 : public SHA3
|
45
|
+
{
|
46
|
+
public:
|
47
|
+
CRYPTOPP_CONSTANT(DIGESTSIZE = 32)
|
48
|
+
CRYPTOPP_CONSTANT(BLOCKSIZE = 136)
|
49
|
+
SHA3_256() : SHA3(DIGESTSIZE) {}
|
50
|
+
static const char * StaticAlgorithmName() {return "SHA-3-256";}
|
51
|
+
};
|
52
|
+
|
53
|
+
class SHA3_384 : public SHA3
|
54
|
+
{
|
55
|
+
public:
|
56
|
+
CRYPTOPP_CONSTANT(DIGESTSIZE = 48)
|
57
|
+
CRYPTOPP_CONSTANT(BLOCKSIZE = 104)
|
58
|
+
SHA3_384() : SHA3(DIGESTSIZE) {}
|
59
|
+
static const char * StaticAlgorithmName() {return "SHA-3-384";}
|
60
|
+
};
|
61
|
+
|
62
|
+
class SHA3_512 : public SHA3
|
63
|
+
{
|
64
|
+
public:
|
65
|
+
CRYPTOPP_CONSTANT(DIGESTSIZE = 64)
|
66
|
+
CRYPTOPP_CONSTANT(BLOCKSIZE = 72)
|
67
|
+
SHA3_512() : SHA3(DIGESTSIZE) {}
|
68
|
+
static const char * StaticAlgorithmName() {return "SHA-3-512";}
|
69
|
+
};
|
70
|
+
|
71
|
+
NAMESPACE_END
|
72
|
+
|
73
|
+
#endif
|
data/ext/jshacal2.cpp
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
2
|
/*
|
3
|
-
* Copyright (c) 2002-
|
4
|
-
* Crypto++ copyright (c) 1995-
|
5
|
-
* See
|
3
|
+
* Copyright (c) 2002-2014 J Smith <dark.panda@gmail.com>
|
4
|
+
* Crypto++ copyright (c) 1995-2013 Wei Dai
|
5
|
+
* See MIT-LICENSE for the extact license
|
6
6
|
*/
|
7
7
|
|
8
8
|
#include "jshacal2.h"
|
@@ -11,12 +11,12 @@
|
|
11
11
|
|
12
12
|
BlockCipher* JSHACAL2::getEncryptionObject()
|
13
13
|
{
|
14
|
-
|
14
|
+
return new SHACAL2Encryption((byte*) itsKey.data(), itsKeylength);
|
15
15
|
}
|
16
16
|
|
17
17
|
BlockCipher* JSHACAL2::getDecryptionObject()
|
18
18
|
{
|
19
|
-
|
19
|
+
return new SHACAL2Decryption((byte*) itsKey.data(), itsKeylength);
|
20
20
|
}
|
21
21
|
|
22
22
|
#endif
|
data/ext/jshacal2.h
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
2
|
/*
|
3
|
-
* Copyright (c) 2002-
|
4
|
-
* Crypto++ copyright (c) 1995-
|
5
|
-
* See
|
3
|
+
* Copyright (c) 2002-2014 J Smith <dark.panda@gmail.com>
|
4
|
+
* Crypto++ copyright (c) 1995-2013 Wei Dai
|
5
|
+
* See MIT-LICENSE for the extact license
|
6
6
|
*/
|
7
7
|
|
8
8
|
#ifndef __JSHACAL2_H__
|
@@ -22,9 +22,9 @@ using namespace CryptoPP;
|
|
22
22
|
|
23
23
|
class JSHACAL2 : public JCipher_Template<SHACAL2_Info, SHACAL2_CIPHER>
|
24
24
|
{
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
protected:
|
26
|
+
BlockCipher* getEncryptionObject();
|
27
|
+
BlockCipher* getDecryptionObject();
|
28
28
|
};
|
29
29
|
|
30
30
|
#endif
|
data/ext/jshark.cpp
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
|
2
2
|
/*
|
3
|
-
* Copyright (c) 2002-
|
4
|
-
* Crypto++ copyright (c) 1995-
|
5
|
-
* See
|
3
|
+
* Copyright (c) 2002-2014 J Smith <dark.panda@gmail.com>
|
4
|
+
* Crypto++ copyright (c) 1995-2013 Wei Dai
|
5
|
+
* See MIT-LICENSE for the extact license
|
6
6
|
*/
|
7
7
|
|
8
8
|
#include "jshark.h"
|
9
9
|
|
10
|
-
#ifdef WORD64_AVAILABLE
|
11
10
|
#if ENABLED_SHARK_CIPHER
|
12
11
|
|
13
12
|
BlockCipher* JSHARK::getEncryptionObject()
|
14
13
|
{
|
15
|
-
|
14
|
+
return new SHARKEncryption((byte*) itsKey.data(), itsKeylength, itsRounds);
|
16
15
|
}
|
17
16
|
|
18
17
|
BlockCipher* JSHARK::getDecryptionObject()
|
19
18
|
{
|
20
|
-
|
19
|
+
return new SHARKDecryption((byte*) itsKey.data(), itsKeylength, itsRounds);
|
21
20
|
}
|
22
21
|
|
23
22
|
#endif
|
24
|
-
#endif
|
data/ext/jshark.h
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
2
|
/*
|
3
|
-
* Copyright (c) 2002-
|
4
|
-
* Crypto++ copyright (c) 1995-
|
5
|
-
* See
|
3
|
+
* Copyright (c) 2002-2014 J Smith <dark.panda@gmail.com>
|
4
|
+
* Crypto++ copyright (c) 1995-2013 Wei Dai
|
5
|
+
* See MIT-LICENSE for the extact license
|
6
6
|
*/
|
7
7
|
|
8
8
|
#ifndef __JSHARK_H__
|
@@ -10,7 +10,6 @@
|
|
10
10
|
|
11
11
|
#include "jconfig.h"
|
12
12
|
|
13
|
-
#ifdef WORD64_AVAILABLE
|
14
13
|
#if ENABLED_SHARK_CIPHER
|
15
14
|
|
16
15
|
#include "jcipher_t.h"
|
@@ -23,11 +22,10 @@ using namespace CryptoPP;
|
|
23
22
|
|
24
23
|
class JSHARK : public JCipher_Template<SHARK_Info, SHARK_CIPHER, 6, 2, INT_MAX>
|
25
24
|
{
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
protected:
|
26
|
+
BlockCipher* getEncryptionObject();
|
27
|
+
BlockCipher* getDecryptionObject();
|
29
28
|
};
|
30
29
|
|
31
30
|
#endif
|
32
31
|
#endif
|
33
|
-
#endif
|
data/ext/jsink.cpp
CHANGED
@@ -1,90 +1,90 @@
|
|
1
1
|
|
2
2
|
/*
|
3
|
-
* Copyright (c) 2002-
|
4
|
-
* Crypto++ copyright (c) 1995-
|
5
|
-
* See
|
3
|
+
* Copyright (c) 2002-2014 J Smith <dark.panda@gmail.com>
|
4
|
+
* Crypto++ copyright (c) 1995-2013 Wei Dai
|
5
|
+
* See MIT-LICENSE for the extact license
|
6
6
|
*/
|
7
7
|
|
8
8
|
#include "jsink.h"
|
9
9
|
|
10
10
|
void RubyIOStore::StoreInitialize(const NameValuePairs& parameters)
|
11
11
|
{
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
m_stream = NULL;
|
13
|
+
parameters.GetValue(Name::InputStreamPointer(), m_stream);
|
14
|
+
m_waiting = false;
|
15
15
|
}
|
16
16
|
|
17
17
|
size_t RubyIOStore::Peek(byte& outByte) const
|
18
18
|
{
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
if (!m_stream || rb_funcall(*m_stream, rb_intern("eof?"), 0)) {
|
20
|
+
return 0;
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
return 1;
|
24
|
+
}
|
25
25
|
}
|
26
26
|
|
27
27
|
|
28
28
|
size_t RubyIOStore::TransferTo2(BufferedTransformation& target, CryptoPP::lword& transferBytes, const std::string& channel, bool blocking)
|
29
29
|
{
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
if (!m_stream) {
|
31
|
+
transferBytes = 0;
|
32
|
+
return 0;
|
33
|
+
}
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
lword size = transferBytes;
|
36
|
+
transferBytes = 0;
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
if (m_waiting) {
|
39
|
+
goto output;
|
40
|
+
}
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
while (size && !RTEST(rb_funcall(*m_stream, rb_intern("eof?"), 0))) {
|
43
|
+
{
|
44
|
+
VALUE buffer;
|
45
|
+
size_t spaceSize = 1024;
|
46
|
+
m_space = HelpCreatePutSpace(target, channel, 1, UnsignedMin(size_t(0) - 1, size), spaceSize);
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
48
|
+
buffer = rb_funcall(*m_stream, rb_intern("read"), 1, UINT2NUM(STDMIN(size, (lword) spaceSize)));
|
49
|
+
if (TYPE(buffer) != T_STRING) {
|
50
|
+
throw ReadErr();
|
51
|
+
}
|
52
|
+
memcpy(m_space, StringValuePtr(buffer), RSTRING_LEN(buffer));
|
53
|
+
m_len = RSTRING_LEN(buffer);
|
54
|
+
}
|
55
|
+
size_t blockedBytes;
|
56
|
+
output:
|
57
|
+
blockedBytes = target.ChannelPutModifiable2(channel, m_space, m_len, 0, blocking);
|
58
|
+
m_waiting = blockedBytes > 0;
|
59
|
+
if (m_waiting) {
|
60
|
+
return blockedBytes;
|
61
|
+
}
|
62
|
+
size -= m_len;
|
63
|
+
transferBytes += m_len;
|
64
|
+
}
|
65
|
+
if (!RTEST(rb_funcall(*m_stream, rb_intern("eof?"), 0))) {
|
66
|
+
throw ReadErr();
|
67
|
+
}
|
68
|
+
return 0;
|
69
69
|
}
|
70
70
|
|
71
71
|
void RubyIOSink::IsolatedInitialize(const NameValuePairs& parameters)
|
72
72
|
{
|
73
|
-
|
74
|
-
|
73
|
+
m_stream = NULL;
|
74
|
+
parameters.GetValue(Name::OutputStreamPointer(), m_stream);
|
75
75
|
}
|
76
76
|
|
77
77
|
size_t RubyIOSink::Put2(const byte* inString, size_t length, int messageEnd, bool blocking)
|
78
78
|
{
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
if (!m_stream) {
|
80
|
+
throw Err("RubyIOSink: output stream not opened");
|
81
|
+
}
|
82
82
|
|
83
|
-
|
83
|
+
rb_funcall(*m_stream, rb_intern("write"), 1, rb_str_new((const char*) inString, length));
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
if (messageEnd) {
|
86
|
+
rb_funcall(*m_stream, rb_intern("flush"), 0);
|
87
|
+
}
|
88
88
|
|
89
|
-
|
89
|
+
return 0;
|
90
90
|
}
|
data/ext/jsink.h
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
2
|
/*
|
3
|
-
* Copyright (c) 2002-
|
4
|
-
* Crypto++ copyright (c) 1995-
|
5
|
-
* See
|
3
|
+
* Copyright (c) 2002-2014 J Smith <dark.panda@gmail.com>
|
4
|
+
* Crypto++ copyright (c) 1995-2013 Wei Dai
|
5
|
+
* See MIT-LICENSE for the extact license
|
6
6
|
*/
|
7
7
|
|
8
8
|
#ifndef __JSINK_H__
|
@@ -13,142 +13,146 @@
|
|
13
13
|
|
14
14
|
extern "C" {
|
15
15
|
#include "ruby.h"
|
16
|
+
|
17
|
+
#if defined(RUBY_VERSION_CODE) && RUBY_VERSION_CODE >= 190
|
18
|
+
#include "ruby/io.h"
|
19
|
+
#else
|
16
20
|
#include "rubyio.h"
|
21
|
+
#endif
|
17
22
|
}
|
18
23
|
|
19
24
|
using namespace CryptoPP;
|
20
25
|
|
21
26
|
class RubyIOStore : public Store, private FilterPutSpaceHelper
|
22
27
|
{
|
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
|
-
bool m_waiting;
|
28
|
+
public:
|
29
|
+
class Err : public Exception
|
30
|
+
{
|
31
|
+
public:
|
32
|
+
Err(const std::string& s) : Exception(IO_ERROR, s) {}
|
33
|
+
};
|
34
|
+
|
35
|
+
class OpenErr : public Err
|
36
|
+
{
|
37
|
+
public:
|
38
|
+
OpenErr(const std::string& filename) : Err("RubyIOStore: error opening IO stream for reading: " + filename) {}
|
39
|
+
};
|
40
|
+
|
41
|
+
class ReadErr : public Err
|
42
|
+
{
|
43
|
+
public:
|
44
|
+
ReadErr() : Err("RubyIOStore: error reading IO stream") {}
|
45
|
+
};
|
46
|
+
|
47
|
+
RubyIOStore() {}
|
48
|
+
|
49
|
+
RubyIOStore(VALUE** in)
|
50
|
+
{
|
51
|
+
StoreInitialize(MakeParameters(Name::InputStreamPointer(), *in));
|
52
|
+
}
|
53
|
+
|
54
|
+
RubyIOStore(const char* filename)
|
55
|
+
{
|
56
|
+
StoreInitialize(MakeParameters(Name::InputFileName(), filename));
|
57
|
+
}
|
58
|
+
|
59
|
+
VALUE* GetStream()
|
60
|
+
{
|
61
|
+
return m_stream;
|
62
|
+
}
|
63
|
+
|
64
|
+
size_t Peek(byte &outByte) const;
|
65
|
+
size_t TransferTo2(BufferedTransformation &target, CryptoPP::lword &transferBytes, const std::string &channel = NULL_CHANNEL, bool blocking = true);
|
66
|
+
|
67
|
+
// These abstract methods are purposely no-ops here...
|
68
|
+
size_t CopyRangeTo2(BufferedTransformation& target, CryptoPP::lword& begin, CryptoPP::lword end = ULONG_MAX, const std::string& channel = NULL_CHANNEL, bool blocking = true) const { return 0; }
|
69
|
+
CryptoPP::lword MaxRetrievable() const { return 0L; }
|
70
|
+
|
71
|
+
private:
|
72
|
+
void StoreInitialize(const NameValuePairs ¶meters);
|
73
|
+
VALUE* m_stream;
|
74
|
+
|
75
|
+
byte* m_space;
|
76
|
+
unsigned int m_len;
|
77
|
+
bool m_waiting;
|
74
78
|
};
|
75
79
|
|
76
80
|
class RubyIOSource : public SourceTemplate<RubyIOStore>
|
77
81
|
{
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
82
|
+
public:
|
83
|
+
typedef RubyIOStore::Err Err;
|
84
|
+
typedef RubyIOStore::OpenErr OpenErr;
|
85
|
+
typedef RubyIOStore::ReadErr ReadErr;
|
86
|
+
|
87
|
+
RubyIOSource(BufferedTransformation* attachment = NULL) : SourceTemplate<RubyIOStore>(attachment) {}
|
88
|
+
|
89
|
+
RubyIOSource(VALUE** in, bool pumpAll, BufferedTransformation* attachment = NULL) : SourceTemplate<RubyIOStore>(attachment)
|
90
|
+
{
|
91
|
+
SourceInitialize(pumpAll, MakeParameters(Name::InputStreamPointer(), *in));
|
92
|
+
}
|
93
|
+
|
94
|
+
RubyIOSource(const char* filename, bool pumpAll, BufferedTransformation* attachment = NULL, bool binary = true) : SourceTemplate<RubyIOStore>(attachment)
|
95
|
+
{
|
96
|
+
SourceInitialize(pumpAll, MakeParameters(Name::InputFileName(), filename)(Name::InputBinaryMode(), binary));
|
97
|
+
}
|
98
|
+
|
99
|
+
VALUE* GetStream()
|
100
|
+
{
|
101
|
+
return m_store.GetStream();
|
102
|
+
}
|
99
103
|
};
|
100
104
|
|
101
105
|
|
102
106
|
class RubyIOSink : public Sink
|
103
107
|
{
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
108
|
+
public:
|
109
|
+
class Err : public Exception
|
110
|
+
{
|
111
|
+
public:
|
112
|
+
Err(const std::string& s) : Exception(IO_ERROR, s) {}
|
113
|
+
};
|
114
|
+
|
115
|
+
class OpenErr : public Err
|
116
|
+
{
|
117
|
+
public:
|
118
|
+
OpenErr(const std::string &filename) : Err("RubyIOSink: error opening file for writing: " + filename) {}
|
119
|
+
};
|
120
|
+
|
121
|
+
class WriteErr : public Err
|
122
|
+
{
|
123
|
+
public:
|
124
|
+
WriteErr() : Err("RubyIOSink: error writing file") {}
|
125
|
+
};
|
126
|
+
|
127
|
+
RubyIOSink()
|
128
|
+
{
|
129
|
+
m_stream = NULL;
|
130
|
+
}
|
131
|
+
|
132
|
+
RubyIOSink(VALUE** out)
|
133
|
+
{
|
134
|
+
IsolatedInitialize(MakeParameters(Name::OutputStreamPointer(), *out));
|
135
|
+
}
|
136
|
+
|
137
|
+
RubyIOSink(const char* filename, bool binary = true)
|
138
|
+
{
|
139
|
+
IsolatedInitialize(MakeParameters(Name::OutputFileName(), filename)(Name::OutputBinaryMode(), binary));
|
140
|
+
}
|
141
|
+
|
142
|
+
VALUE* GetStream()
|
143
|
+
{
|
144
|
+
return m_stream;
|
145
|
+
}
|
146
|
+
|
147
|
+
void IsolatedInitialize(const NameValuePairs& parameters);
|
148
|
+
size_t Put2(const byte* inString, size_t length, int messageEnd, bool blocking);
|
149
|
+
|
150
|
+
// IsolatedFlush isn't actually used, but needs to be implemented because
|
151
|
+
// it's abstract...
|
152
|
+
bool IsolatedFlush(bool hardFlush, bool blocking) { return false; };
|
153
|
+
|
154
|
+
private:
|
155
|
+
VALUE* m_stream;
|
152
156
|
};
|
153
157
|
|
154
158
|
#endif
|