cryptopp 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/.gitignore +8 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README +7 -0
  4. data/Rakefile +42 -0
  5. data/cryptopp.gemspec +199 -0
  6. data/ext/.gitignore +5 -0
  7. data/ext/Rakefile +16 -0
  8. data/ext/ciphers.cpp +1402 -0
  9. data/ext/cryptopp.cpp +285 -0
  10. data/ext/cryptopp_ruby_api.h +139 -0
  11. data/ext/defs/block_modes.def +10 -0
  12. data/ext/defs/checksums.def +10 -0
  13. data/ext/defs/ciphers.def +136 -0
  14. data/ext/defs/hashes.def +78 -0
  15. data/ext/defs/hmacs.def +54 -0
  16. data/ext/defs/paddings.def +9 -0
  17. data/ext/defs/rngs.def +7 -0
  18. data/ext/digests.cpp +1120 -0
  19. data/ext/extconf.rb +39 -0
  20. data/ext/j3way.cpp +22 -0
  21. data/ext/j3way.h +29 -0
  22. data/ext/jadler32.h +32 -0
  23. data/ext/jaes.cpp +22 -0
  24. data/ext/jaes.h +31 -0
  25. data/ext/jarc4.cpp +22 -0
  26. data/ext/jarc4.h +37 -0
  27. data/ext/jbase.cpp +172 -0
  28. data/ext/jbase.h +92 -0
  29. data/ext/jbasiccipherinfo.h +74 -0
  30. data/ext/jblowfish.cpp +22 -0
  31. data/ext/jblowfish.h +29 -0
  32. data/ext/jcamellia.cpp +24 -0
  33. data/ext/jcamellia.h +33 -0
  34. data/ext/jcast128.cpp +22 -0
  35. data/ext/jcast128.h +31 -0
  36. data/ext/jcast256.cpp +22 -0
  37. data/ext/jcast256.h +31 -0
  38. data/ext/jcipher.cpp +112 -0
  39. data/ext/jcipher.h +42 -0
  40. data/ext/jcipher_t.h +469 -0
  41. data/ext/jconfig.h +127 -0
  42. data/ext/jconstants.h +189 -0
  43. data/ext/jcrc32.h +32 -0
  44. data/ext/jdes.cpp +22 -0
  45. data/ext/jdes.h +31 -0
  46. data/ext/jdes_ede2.cpp +22 -0
  47. data/ext/jdes_ede2.h +31 -0
  48. data/ext/jdes_ede3.cpp +22 -0
  49. data/ext/jdes_ede3.h +31 -0
  50. data/ext/jdes_xex3.cpp +22 -0
  51. data/ext/jdes_xex3.h +31 -0
  52. data/ext/jdiamond2.cpp +22 -0
  53. data/ext/jdiamond2.h +31 -0
  54. data/ext/jdiamond2lite.cpp +22 -0
  55. data/ext/jdiamond2lite.h +31 -0
  56. data/ext/jexception.h +20 -0
  57. data/ext/jgost.cpp +22 -0
  58. data/ext/jgost.h +31 -0
  59. data/ext/jhash.cpp +92 -0
  60. data/ext/jhash.h +54 -0
  61. data/ext/jhash_t.h +121 -0
  62. data/ext/jhaval.h +64 -0
  63. data/ext/jhelpers.cpp +90 -0
  64. data/ext/jhelpers.h +38 -0
  65. data/ext/jhmac.cpp +44 -0
  66. data/ext/jhmac.h +34 -0
  67. data/ext/jhmac_t.h +125 -0
  68. data/ext/jidea.cpp +22 -0
  69. data/ext/jidea.h +31 -0
  70. data/ext/jmarc4.cpp +22 -0
  71. data/ext/jmarc4.h +37 -0
  72. data/ext/jmars.cpp +22 -0
  73. data/ext/jmars.h +31 -0
  74. data/ext/jmd2.h +56 -0
  75. data/ext/jmd4.h +56 -0
  76. data/ext/jmd5.h +56 -0
  77. data/ext/jpanamacipher.cpp +32 -0
  78. data/ext/jpanamacipher.h +46 -0
  79. data/ext/jpanamahash.h +44 -0
  80. data/ext/jrc2.cpp +44 -0
  81. data/ext/jrc2.h +39 -0
  82. data/ext/jrc5.cpp +22 -0
  83. data/ext/jrc5.h +31 -0
  84. data/ext/jrc6.cpp +22 -0
  85. data/ext/jrc6.h +31 -0
  86. data/ext/jripemd160.h +113 -0
  87. data/ext/jsafer.cpp +32 -0
  88. data/ext/jsafer.h +42 -0
  89. data/ext/jseal.cpp +32 -0
  90. data/ext/jseal.h +42 -0
  91. data/ext/jserpent.cpp +22 -0
  92. data/ext/jserpent.h +31 -0
  93. data/ext/jsha.h +122 -0
  94. data/ext/jshacal2.cpp +22 -0
  95. data/ext/jshacal2.h +31 -0
  96. data/ext/jshark.cpp +24 -0
  97. data/ext/jshark.h +33 -0
  98. data/ext/jsink.cpp +90 -0
  99. data/ext/jsink.h +154 -0
  100. data/ext/jskipjack.cpp +22 -0
  101. data/ext/jskipjack.h +31 -0
  102. data/ext/jsquare.cpp +22 -0
  103. data/ext/jsquare.h +31 -0
  104. data/ext/jstream.cpp +8 -0
  105. data/ext/jstream.h +20 -0
  106. data/ext/jstream_t.h +175 -0
  107. data/ext/jtea.cpp +22 -0
  108. data/ext/jtea.h +31 -0
  109. data/ext/jtiger.h +52 -0
  110. data/ext/jtwofish.cpp +22 -0
  111. data/ext/jtwofish.h +31 -0
  112. data/ext/jwhirlpool.h +52 -0
  113. data/ext/utils.cpp +8 -0
  114. data/extras/parser_c.rb +114 -0
  115. data/test/ciphers_test.rb +37 -0
  116. data/test/data/ciphers/3desval.dat +7 -0
  117. data/test/data/ciphers/3wayval.dat +6 -0
  118. data/test/data/ciphers/arc4.dat +8 -0
  119. data/test/data/ciphers/blowfish.dat +5 -0
  120. data/test/data/ciphers/camellia.dat +7 -0
  121. data/test/data/ciphers/cast128v.dat +5 -0
  122. data/test/data/ciphers/cast256v.dat +5 -0
  123. data/test/data/ciphers/descert.dat +198 -0
  124. data/test/data/ciphers/diamond.dat +9 -0
  125. data/test/data/ciphers/gostval.dat +10 -0
  126. data/test/data/ciphers/ideaval.dat +13 -0
  127. data/test/data/ciphers/marsval.dat +11 -0
  128. data/test/data/ciphers/panamac.dat +7 -0
  129. data/test/data/ciphers/rc2val.dat +10 -0
  130. data/test/data/ciphers/rc5val.dat +7 -0
  131. data/test/data/ciphers/rc6val.dat +8 -0
  132. data/test/data/ciphers/rijndael.dat +11 -0
  133. data/test/data/ciphers/saferval.dat +27 -0
  134. data/test/data/ciphers/seal.dat +3 -0
  135. data/test/data/ciphers/serpentv.dat +11 -0
  136. data/test/data/ciphers/shacal2.dat +7 -0
  137. data/test/data/ciphers/sharkval.dat +9 -0
  138. data/test/data/ciphers/skipjack.dat +3 -0
  139. data/test/data/ciphers/squareva.dat +10 -0
  140. data/test/data/ciphers/twofishv.dat +11 -0
  141. data/test/data/digests/adler32.dat +8 -0
  142. data/test/data/digests/crc32.dat +10 -0
  143. data/test/data/digests/haval.dat +4 -0
  144. data/test/data/digests/havalcer.dat +23 -0
  145. data/test/data/digests/md2.dat +9 -0
  146. data/test/data/digests/md4.dat +9 -0
  147. data/test/data/digests/md5.dat +9 -0
  148. data/test/data/digests/panamah.dat +8 -0
  149. data/test/data/digests/ripemd.dat +43 -0
  150. data/test/data/digests/sha.dat +19 -0
  151. data/test/data/digests/tiger.dat +11 -0
  152. data/test/data/digests/whirlpool.dat +13 -0
  153. data/test/data/hmacs/hmac.dat +6 -0
  154. data/test/digests_test.rb +29 -0
  155. data/test/hmacs_test.rb +38 -0
  156. data/test/test_helper.rb +42 -0
  157. metadata +220 -0
@@ -0,0 +1,22 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #include "jserpent.h"
9
+
10
+ #if ENABLED_SERPENT_CIPHER
11
+
12
+ BlockCipher* JSerpent::getEncryptionObject()
13
+ {
14
+ return new SerpentEncryption((byte*) itsKey.data(), itsKeylength);
15
+ }
16
+
17
+ BlockCipher* JSerpent::getDecryptionObject()
18
+ {
19
+ return new SerpentDecryption((byte*) itsKey.data(), itsKeylength);
20
+ }
21
+
22
+ #endif
@@ -0,0 +1,31 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #ifndef __JSERPENT_H__
9
+ #define __JSERPENT_H__
10
+
11
+ #include "jconfig.h"
12
+
13
+ #if ENABLED_SERPENT_CIPHER
14
+
15
+ #include "jcipher_t.h"
16
+
17
+ // Crypto++ headers...
18
+
19
+ #include "serpent.h"
20
+
21
+ using namespace CryptoPP;
22
+
23
+ class JSerpent : public JCipher_Template<Serpent_Info, SERPENT_CIPHER>
24
+ {
25
+ protected:
26
+ BlockCipher* getEncryptionObject();
27
+ BlockCipher* getDecryptionObject();
28
+ };
29
+
30
+ #endif
31
+ #endif
@@ -0,0 +1,122 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #ifndef __JSHA_H__
9
+ #define __JSHA_H__
10
+
11
+ #include "jconfig.h"
12
+
13
+ #if ENABLED_SHA1_HASH || ENABLED_SHA256_HASH || (defined(WORD64_AVAILABLE) && (ENABLED_SHA384_HASH || ENABLED_SHA512_HASH)) || \
14
+ ENABLED_SHA1_HMAC || ENABLED_SHA256_HMAC || (defined(WORD64_AVAILABLE) && (ENABLED_SHA384_HMAC || ENABLED_SHA512_HMAC))
15
+
16
+ #if ENABLED_SHA1_HASH || ENABLED_SHA256_HASH || (defined(WORD64_AVAILABLE) && (ENABLED_SHA384_HASH || ENABLED_SHA512_HASH))
17
+ #include "jhash_t.h"
18
+ #endif
19
+
20
+ #if ENABLED_SHA1_HMAC || ENABLED_SHA256_HMAC || (defined(WORD64_AVAILABLE) && (ENABLED_SHA384_HMAC || ENABLED_SHA512_HMAC))
21
+ #include "jhmac_t.h"
22
+ #endif
23
+
24
+
25
+ // Crypto++ headers...
26
+
27
+ #include "sha.h"
28
+
29
+ using namespace CryptoPP;
30
+
31
+ #if ENABLED_SHA1_HASH
32
+ class JSHA1 : public JHash_Template<SHA1, SHA1_HASH>
33
+ {
34
+ public:
35
+ JSHA1(string plaintext = "") : JHash_Template<SHA1, SHA1_HASH>(plaintext) { }
36
+
37
+ static string getHashName() { return "SHA1"; }
38
+ };
39
+
40
+ typedef JSHA1 JSHA;
41
+ #endif
42
+
43
+ #if ENABLED_SHA256_HASH
44
+ class JSHA256 : public JHash_Template<SHA256, SHA256_HASH>
45
+ {
46
+ public:
47
+ JSHA256(string plaintext = "") : JHash_Template<SHA256, SHA256_HASH>(plaintext) { }
48
+
49
+ static string getHashName() { return "SHA-256"; }
50
+ };
51
+ #endif
52
+
53
+ #ifdef WORD64_AVAILABLE
54
+ #if ENABLED_SHA384_HASH
55
+ class JSHA384 : public JHash_Template<SHA384, SHA384_HASH>
56
+ {
57
+ public:
58
+ JSHA384(string plaintext = "") : JHash_Template<SHA384, SHA384_HASH>(plaintext) { }
59
+
60
+ static string getHashName() { return "SHA-384"; }
61
+ };
62
+ #endif
63
+
64
+ #if ENABLED_SHA512_HASH
65
+ class JSHA512 : public JHash_Template<SHA512, SHA512_HASH>
66
+ {
67
+ public:
68
+ JSHA512(string plaintext = "") : JHash_Template<SHA512, SHA512_HASH>(plaintext) { }
69
+
70
+ static string getHashName() { return "SHA-512"; }
71
+ };
72
+ #endif
73
+ #endif
74
+
75
+
76
+ #if ENABLED_SHA1_HMAC
77
+ class JSHA1_HMAC : public JHMAC_Template<SHA1, SHA1_HMAC>
78
+ {
79
+ public:
80
+ JSHA1_HMAC(string plaintext = "") : JHMAC_Template<SHA1, SHA1_HMAC>(plaintext) { }
81
+
82
+ static string getHashName() { return "SHA1-HMAC"; }
83
+ };
84
+
85
+ typedef JSHA1_HMAC JSHA_HMAC;
86
+ #endif
87
+
88
+ #if ENABLED_SHA256_HMAC
89
+ class JSHA256_HMAC : public JHMAC_Template<SHA256, SHA256_HMAC>
90
+ {
91
+ public:
92
+ JSHA256_HMAC(string plaintext = "") : JHMAC_Template<SHA256, SHA256_HMAC>(plaintext) { }
93
+
94
+ static string getHashName() { return "SHA-256-HMAC"; }
95
+ };
96
+ #endif
97
+
98
+ #ifdef WORD64_AVAILABLE
99
+ #if ENABLED_SHA384_HMAC
100
+ class JSHA384_HMAC : public JHMAC_Template<SHA384, SHA384_HMAC>
101
+ {
102
+ public:
103
+ JSHA384_HMAC(string plaintext = "") : JHMAC_Template<SHA384, SHA384_HMAC>(plaintext) { }
104
+
105
+ static string getHashName() { return "SHA-384-HMAC"; }
106
+ };
107
+ #endif
108
+
109
+ #if ENABLED_SHA512_HMAC
110
+ class JSHA512_HMAC : public JHMAC_Template<SHA512, SHA512_HMAC>
111
+ {
112
+ public:
113
+ JSHA512_HMAC(string plaintext = "") : JHMAC_Template<SHA512, SHA512_HMAC>(plaintext) { }
114
+
115
+ static string getHashName() { return "SHA-512-HMAC"; }
116
+ };
117
+ #endif
118
+ #endif
119
+
120
+
121
+ #endif
122
+ #endif
@@ -0,0 +1,22 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #include "jshacal2.h"
9
+
10
+ #if ENABLED_SHACAL2_CIPHER
11
+
12
+ BlockCipher* JSHACAL2::getEncryptionObject()
13
+ {
14
+ return new SHACAL2Encryption((byte*) itsKey.data(), itsKeylength);
15
+ }
16
+
17
+ BlockCipher* JSHACAL2::getDecryptionObject()
18
+ {
19
+ return new SHACAL2Decryption((byte*) itsKey.data(), itsKeylength);
20
+ }
21
+
22
+ #endif
@@ -0,0 +1,31 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #ifndef __JSHACAL2_H__
9
+ #define __JSHACAL2_H__
10
+
11
+ #include "jconfig.h"
12
+
13
+ #if ENABLED_SHACAL2_CIPHER
14
+
15
+ #include "jcipher_t.h"
16
+
17
+ // Crypto++ headers...
18
+
19
+ #include "shacal2.h"
20
+
21
+ using namespace CryptoPP;
22
+
23
+ class JSHACAL2 : public JCipher_Template<SHACAL2_Info, SHACAL2_CIPHER>
24
+ {
25
+ protected:
26
+ BlockCipher* getEncryptionObject();
27
+ BlockCipher* getDecryptionObject();
28
+ };
29
+
30
+ #endif
31
+ #endif
@@ -0,0 +1,24 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #include "jshark.h"
9
+
10
+ #ifdef WORD64_AVAILABLE
11
+ #if ENABLED_SHARK_CIPHER
12
+
13
+ BlockCipher* JSHARK::getEncryptionObject()
14
+ {
15
+ return new SHARKEncryption((byte*) itsKey.data(), itsKeylength, itsRounds);
16
+ }
17
+
18
+ BlockCipher* JSHARK::getDecryptionObject()
19
+ {
20
+ return new SHARKDecryption((byte*) itsKey.data(), itsKeylength, itsRounds);
21
+ }
22
+
23
+ #endif
24
+ #endif
@@ -0,0 +1,33 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #ifndef __JSHARK_H__
9
+ #define __JSHARK_H__
10
+
11
+ #include "jconfig.h"
12
+
13
+ #ifdef WORD64_AVAILABLE
14
+ #if ENABLED_SHARK_CIPHER
15
+
16
+ #include "jcipher_t.h"
17
+
18
+ // Crypto++ headers...
19
+
20
+ #include "shark.h"
21
+
22
+ using namespace CryptoPP;
23
+
24
+ class JSHARK : public JCipher_Template<SHARK_Info, SHARK_CIPHER, 6, 2, INT_MAX>
25
+ {
26
+ protected:
27
+ BlockCipher* getEncryptionObject();
28
+ BlockCipher* getDecryptionObject();
29
+ };
30
+
31
+ #endif
32
+ #endif
33
+ #endif
@@ -0,0 +1,90 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #include "jsink.h"
9
+
10
+ void RubyIOStore::StoreInitialize(const NameValuePairs& parameters)
11
+ {
12
+ m_stream = NULL;
13
+ parameters.GetValue(Name::InputStreamPointer(), m_stream);
14
+ m_waiting = false;
15
+ }
16
+
17
+ size_t RubyIOStore::Peek(byte& outByte) const
18
+ {
19
+ if (!m_stream || rb_funcall(*m_stream, rb_intern("eof?"), 0)) {
20
+ return 0;
21
+ }
22
+ else {
23
+ return 1;
24
+ }
25
+ }
26
+
27
+
28
+ size_t RubyIOStore::TransferTo2(BufferedTransformation& target, CryptoPP::lword& transferBytes, const std::string& channel, bool blocking)
29
+ {
30
+ if (!m_stream) {
31
+ transferBytes = 0;
32
+ return 0;
33
+ }
34
+
35
+ lword size = transferBytes;
36
+ transferBytes = 0;
37
+
38
+ if (m_waiting) {
39
+ goto output;
40
+ }
41
+
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
+
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(buffer)->len);
53
+ m_len = RSTRING(buffer)->len;
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
+ }
70
+
71
+ void RubyIOSink::IsolatedInitialize(const NameValuePairs& parameters)
72
+ {
73
+ m_stream = NULL;
74
+ parameters.GetValue(Name::OutputStreamPointer(), m_stream);
75
+ }
76
+
77
+ size_t RubyIOSink::Put2(const byte* inString, size_t length, int messageEnd, bool blocking)
78
+ {
79
+ if (!m_stream) {
80
+ throw Err("RubyIOSink: output stream not opened");
81
+ }
82
+
83
+ rb_funcall(*m_stream, rb_intern("write"), 1, rb_str_new((const char*) inString, length));
84
+
85
+ if (messageEnd) {
86
+ rb_funcall(*m_stream, rb_intern("flush"), 0);
87
+ }
88
+
89
+ return 0;
90
+ }
@@ -0,0 +1,154 @@
1
+
2
+ /*
3
+ * Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
4
+ * Crypto++ copyright (c) 1995-2010 Wei Dai
5
+ * See COPYING for the extact license
6
+ */
7
+
8
+ #ifndef __JSINK_H__
9
+ #define __JSINK_H__
10
+
11
+ #include "filters.h"
12
+ #include "argnames.h"
13
+
14
+ extern "C" {
15
+ #include "ruby.h"
16
+ #include "rubyio.h"
17
+ }
18
+
19
+ using namespace CryptoPP;
20
+
21
+ class RubyIOStore : public Store, private FilterPutSpaceHelper
22
+ {
23
+ public:
24
+ class Err : public Exception
25
+ {
26
+ public:
27
+ Err(const std::string& s) : Exception(IO_ERROR, s) {}
28
+ };
29
+
30
+ class OpenErr : public Err
31
+ {
32
+ public:
33
+ OpenErr(const std::string& filename) : Err("RubyIOStore: error opening IO stream for reading: " + filename) {}
34
+ };
35
+
36
+ class ReadErr : public Err
37
+ {
38
+ public:
39
+ ReadErr() : Err("RubyIOStore: error reading IO stream") {}
40
+ };
41
+
42
+ RubyIOStore() {}
43
+
44
+ RubyIOStore(VALUE** in)
45
+ {
46
+ StoreInitialize(MakeParameters(Name::InputStreamPointer(), *in));
47
+ }
48
+
49
+ RubyIOStore(const char* filename)
50
+ {
51
+ StoreInitialize(MakeParameters(Name::InputFileName(), filename));
52
+ }
53
+
54
+ VALUE* GetStream()
55
+ {
56
+ return m_stream;
57
+ }
58
+
59
+ size_t Peek(byte &outByte) const;
60
+ size_t TransferTo2(BufferedTransformation &target, CryptoPP::lword &transferBytes, const std::string &channel = NULL_CHANNEL, bool blocking = true);
61
+
62
+ // These methods aren't actually used in the PHP extension, but we need to implement them anyway
63
+ // because they're abstract...
64
+ 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; }
65
+ CryptoPP::lword MaxRetrievable() const { return 0L; }
66
+
67
+ private:
68
+ void StoreInitialize(const NameValuePairs &parameters);
69
+ VALUE* m_stream;
70
+
71
+ byte* m_space;
72
+ unsigned int m_len;
73
+ bool m_waiting;
74
+ };
75
+
76
+ class RubyIOSource : public SourceTemplate<RubyIOStore>
77
+ {
78
+ public:
79
+ typedef RubyIOStore::Err Err;
80
+ typedef RubyIOStore::OpenErr OpenErr;
81
+ typedef RubyIOStore::ReadErr ReadErr;
82
+
83
+ RubyIOSource(BufferedTransformation* attachment = NULL) : SourceTemplate<RubyIOStore>(attachment) {}
84
+
85
+ RubyIOSource(VALUE** in, bool pumpAll, BufferedTransformation* attachment = NULL) : SourceTemplate<RubyIOStore>(attachment)
86
+ {
87
+ SourceInitialize(pumpAll, MakeParameters(Name::InputStreamPointer(), *in));
88
+ }
89
+
90
+ RubyIOSource(const char* filename, bool pumpAll, BufferedTransformation* attachment = NULL, bool binary = true) : SourceTemplate<RubyIOStore>(attachment)
91
+ {
92
+ SourceInitialize(pumpAll, MakeParameters(Name::InputFileName(), filename)(Name::InputBinaryMode(), binary));
93
+ }
94
+
95
+ VALUE* GetStream()
96
+ {
97
+ return m_store.GetStream();
98
+ }
99
+ };
100
+
101
+
102
+ class RubyIOSink : public Sink
103
+ {
104
+ public:
105
+ class Err : public Exception
106
+ {
107
+ public:
108
+ Err(const std::string& s) : Exception(IO_ERROR, s) {}
109
+ };
110
+
111
+ class OpenErr : public Err
112
+ {
113
+ public:
114
+ OpenErr(const std::string &filename) : Err("RubyIOSink: error opening file for writing: " + filename) {}
115
+ };
116
+
117
+ class WriteErr : public Err
118
+ {
119
+ public:
120
+ WriteErr() : Err("RubyIOSink: error writing file") {}
121
+ };
122
+
123
+ RubyIOSink()
124
+ {
125
+ m_stream = NULL;
126
+ }
127
+
128
+ RubyIOSink(VALUE** out)
129
+ {
130
+ IsolatedInitialize(MakeParameters(Name::OutputStreamPointer(), *out));
131
+ }
132
+
133
+ RubyIOSink(const char* filename, bool binary = true)
134
+ {
135
+ IsolatedInitialize(MakeParameters(Name::OutputFileName(), filename)(Name::OutputBinaryMode(), binary));
136
+ }
137
+
138
+ VALUE* GetStream()
139
+ {
140
+ return m_stream;
141
+ }
142
+
143
+ void IsolatedInitialize(const NameValuePairs& parameters);
144
+ size_t Put2(const byte* inString, size_t length, int messageEnd, bool blocking);
145
+
146
+ // IsolatedFlush isn't actually used, but needs to be implemented because
147
+ // it's abstract...
148
+ bool IsolatedFlush(bool hardFlush, bool blocking) { return false; };
149
+
150
+ private:
151
+ VALUE* m_stream;
152
+ };
153
+
154
+ #endif