summaryrefslogtreecommitdiff
path: root/cypher.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2007-06-17 22:25:20 +0000
committerChristian Pointner <equinox@anytun.org>2007-06-17 22:25:20 +0000
commit261c9067380c5311c98e3576540eee6015be3297 (patch)
treef384eb8edbcc4d35793071090839453bcb4418a4 /cypher.cpp
parentadded cypher and authalgo (diff)
added [] - operator to Buffer
const Buffers are now possible
Diffstat (limited to 'cypher.cpp')
-rw-r--r--cypher.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/cypher.cpp b/cypher.cpp
index 8711862..58b433f 100644
--- a/cypher.cpp
+++ b/cypher.cpp
@@ -28,6 +28,8 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <stdexcept>
+
#include "datatypes.h"
#include "cypher.h"
@@ -35,16 +37,19 @@
void Cypher::cypher(Buffer& buf)
{
Buffer stream = getBitStream(buf.getLength());
- calc(buf, stream, buf.getLength());
+ exor(buf, stream);
}
-void Cypher::calc(u_int8_t* buf, u_int8_t* bit_stream, u_int32_t length)
+void Cypher::exor(Buffer& buf, const Buffer& bit_stream)
{
- for(u_int32_t i; i<length; ++i)
- buf[i] ^= bit_stream[i];
+ try
+ {
+ for(u_int32_t i; i<buf.getLength(); ++i)
+ buf[i] ^= bit_stream[i];
+ }
+ catch(std::out_of_range& o) {}
}
-
Buffer NullCypher::getBitStream(u_int32_t length)
{
Buffer buf(length);