aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2015-10-14 16:32:17 -0400
committerJack Lloyd <[email protected]>2015-10-14 16:32:17 -0400
commit39052451400dd9beb12c350d87c2d48ff476210e (patch)
tree0b0a87bcaf47c70e48df39808cd70c549d71668f /src/lib
parentaad256035d4ecb9c4e87a7698f74f6f3178da0e2 (diff)
Move DataSource to utils and rewrite PEM encoding to avoid filters
Removes filters as as an internal dependency pretty much entirely (outside of some dusty corners in misc).
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/asn1/info.txt1
-rw-r--r--src/lib/ffi/info.txt1
-rw-r--r--src/lib/filters/info.txt2
-rw-r--r--src/lib/misc/pem/info.txt2
-rw-r--r--src/lib/misc/pem/pem.cpp41
-rw-r--r--src/lib/pubkey/x509_key.h2
-rw-r--r--src/lib/utils/data_src.cpp (renamed from src/lib/filters/data_src.cpp)0
-rw-r--r--src/lib/utils/data_src.h (renamed from src/lib/filters/data_src.h)0
-rw-r--r--src/lib/utils/info.txt1
9 files changed, 33 insertions, 17 deletions
diff --git a/src/lib/asn1/info.txt b/src/lib/asn1/info.txt
index c6c3db537..a067168e4 100644
--- a/src/lib/asn1/info.txt
+++ b/src/lib/asn1/info.txt
@@ -3,7 +3,6 @@ define ASN1 20131128
load_on auto
<requires>
-filters
bigint
oid_lookup
</requires>
diff --git a/src/lib/ffi/info.txt b/src/lib/ffi/info.txt
index 8d6c5237e..4018e4064 100644
--- a/src/lib/ffi/info.txt
+++ b/src/lib/ffi/info.txt
@@ -2,7 +2,6 @@ define FFI 20151001
<requires>
aead
-filters
kdf
pbkdf
pubkey
diff --git a/src/lib/filters/info.txt b/src/lib/filters/info.txt
index da6827833..fbecd9c87 100644
--- a/src/lib/filters/info.txt
+++ b/src/lib/filters/info.txt
@@ -6,7 +6,6 @@ basefilt.cpp
buf_filt.cpp
comp_filter.cpp
data_snk.cpp
-data_src.cpp
filter.cpp
key_filt.cpp
out_buf.cpp
@@ -23,7 +22,6 @@ basefilt.h
buf_filt.h
data_snk.h
comp_filter.h
-data_src.h
filter.h
filters.h
key_filt.h
diff --git a/src/lib/misc/pem/info.txt b/src/lib/misc/pem/info.txt
index c614b5ca7..9340a7cef 100644
--- a/src/lib/misc/pem/info.txt
+++ b/src/lib/misc/pem/info.txt
@@ -1,5 +1,5 @@
define PEM_CODEC 20131128
<requires>
-codec_filt
+base64
</requires>
diff --git a/src/lib/misc/pem/pem.cpp b/src/lib/misc/pem/pem.cpp
index f33016c70..1279b665e 100644
--- a/src/lib/misc/pem/pem.cpp
+++ b/src/lib/misc/pem/pem.cpp
@@ -6,25 +6,45 @@
*/
#include <botan/pem.h>
-#include <botan/filters.h>
+#include <botan/base64.h>
#include <botan/parsing.h>
namespace Botan {
namespace PEM_Code {
+namespace {
+
+std::string linewrap(size_t width, const std::string& in)
+ {
+ std::string out;
+ for(size_t i = 0; i != in.size(); ++i)
+ {
+ if(i > 0 && i % width == 0)
+ {
+ out.push_back('\n');
+ }
+ out.push_back(in[i]);
+ }
+ if(out.size() > 0 && out[out.size()-1] != '\n')
+ {
+ out.push_back('\n');
+ }
+
+ return out;
+ }
+
+}
+
/*
* PEM encode BER/DER-encoded objects
*/
-std::string encode(const byte der[], size_t length, const std::string& label,
- size_t width)
+std::string encode(const byte der[], size_t length, const std::string& label, size_t width)
{
const std::string PEM_HEADER = "-----BEGIN " + label + "-----\n";
const std::string PEM_TRAILER = "-----END " + label + "-----\n";
- Pipe pipe(new Base64_Encoder(true, width));
- pipe.process_msg(der, length);
- return (PEM_HEADER + pipe.read_all_as_string() + PEM_TRAILER);
+ return (PEM_HEADER + linewrap(width, base64_encode(der, length)) + PEM_TRAILER);
}
/*
@@ -79,8 +99,7 @@ secure_vector<byte> decode(DataSource& source, std::string& label)
label += static_cast<char>(b);
}
- Pipe base64(new Base64_Decoder);
- base64.start_msg();
+ std::vector<char> b64;
const std::string PEM_TRAILER = "-----END " + label + "-----";
position = 0;
@@ -95,10 +114,10 @@ secure_vector<byte> decode(DataSource& source, std::string& label)
throw Decoding_Error("PEM: Malformed PEM trailer");
if(position == 0)
- base64.write(b);
+ b64.push_back(b);
}
- base64.end_msg();
- return base64.read_all();
+
+ return base64_decode(b64.data(), b64.size());
}
secure_vector<byte> decode_check_label(const std::string& pem,
diff --git a/src/lib/pubkey/x509_key.h b/src/lib/pubkey/x509_key.h
index 1bfa248ff..cbb0412d2 100644
--- a/src/lib/pubkey/x509_key.h
+++ b/src/lib/pubkey/x509_key.h
@@ -10,7 +10,7 @@
#include <botan/pk_keys.h>
#include <botan/alg_id.h>
-#include <botan/pipe.h>
+#include <botan/data_src.h>
#include <string>
namespace Botan {
diff --git a/src/lib/filters/data_src.cpp b/src/lib/utils/data_src.cpp
index 4e0725943..4e0725943 100644
--- a/src/lib/filters/data_src.cpp
+++ b/src/lib/utils/data_src.cpp
diff --git a/src/lib/filters/data_src.h b/src/lib/utils/data_src.h
index 2b6998448..2b6998448 100644
--- a/src/lib/filters/data_src.h
+++ b/src/lib/utils/data_src.h
diff --git a/src/lib/utils/info.txt b/src/lib/utils/info.txt
index 7d3216b1c..79026d7a9 100644
--- a/src/lib/utils/info.txt
+++ b/src/lib/utils/info.txt
@@ -9,6 +9,7 @@ calendar.h
charset.h
cpuid.h
database.h
+data_src.h
exceptn.h
loadstor.h
mem_ops.h