add support for "binary strings" that are base64-encoded at the JSON-RPC interface. import_key() uses that now, so bump ServerVersion to 0.21.0 for this incompatible API change.

new_sync
Roker 3 years ago
parent 9b3a05f574
commit c2db69c23f

@ -16,3 +16,6 @@ Out<c_string, ParamFlag::DontOwn>::~Out()
template<>
In<size_t, ParamFlag::NoInput>::~In()
{}
template<>
js::Value Type2String<binary_string>::get() { return "BinaryString"; }

@ -10,11 +10,17 @@
#include <string>
#include "inout.hh"
#include "base64.hh"
// just an empty tag type
// just empty tag types:
// UTF-8 NFC strings:
struct c_string
{ };
// "binary" strings. Always base64-encoded at JSON-RPC side
struct binary_string
{ };
template<ParamFlag PF>
struct In<c_string, PF>
@ -48,6 +54,40 @@ struct In<c_string, PF>
const std::string value;
};
template<ParamFlag PF>
struct In<binary_string, PF>
{
typedef In<binary_string, PF> Self;
typedef const char* c_type;
enum { is_output = false, need_input = !(PF & ParamFlag::NoInput) };
~In() = default;
In(const Self& other) = delete;
In(Self&& victim) = delete;
Self& operator=(const Self&) = delete;
In(const js::Value& v, Context* ctx, unsigned param_nr)
: is_null ( v.is_null() )
, value( bool(PF & ParamFlag::NullOkay) && is_null ? "" : base64_decode(from_json<std::string>(v)) )
{
ctx->store(param_nr, value.length());
}
js::Value to_json() const
{
return is_null ? js::Value{} : ::to_json<std::string>(base64_encode(value));
}
c_type get_value() const { return is_null ? nullptr : value.data(); }
const bool is_null;
const std::string value;
};
template<ParamFlag PF>
struct Out<c_string, PF>

@ -114,7 +114,7 @@ const FunctionMap functions = {
FP( "Low level Key Management API", new Separator),
FP( "generate_keypair", new Func<PEP_STATUS, In_Pep_Session, InOut<pEp_identity*>> ( &generate_keypair) ),
FP( "delete_keypair", new Func<PEP_STATUS, In_Pep_Session, In<c_string>> ( &delete_keypair) ),
FP( "import_key" , new Func<PEP_STATUS, In_Pep_Session, In<c_string>, In<std::size_t>, Out<identity_list*>> ( &import_key) ),
FP( "import_key" , new Func<PEP_STATUS, In_Pep_Session, In<binary_string>, InLength<>, Out<identity_list*>> ( &import_key) ),
FP( "export_key" , new Func<PEP_STATUS, In_Pep_Session, In<c_string>, Out<char*>, Out<std::size_t>> ( &export_key) ),
FP( "find_keys" , new Func<PEP_STATUS, In_Pep_Session, In<c_string>, Out<stringlist_t*>> ( &find_keys) ),
FP( "get_trust" , new Func<PEP_STATUS, In_Pep_Session, InOut<pEp_identity*>> ( &get_trust) ),

@ -108,7 +108,8 @@ const ServerVersion& server_version()
// 0.19 was skipped intentionally.
//static const ServerVersion sv(0,20,0); // JSON-152: 2-parameter version of pollForEvents().
static const ServerVersion sv(0,20,1); // JSON-153: passphrase support
//static const ServerVersion sv(0,20,1); // JSON-153: passphrase support
static const ServerVersion sv(0,21,0); // import_key() expects binary data, so they are always base64-encoded!
return sv;
}

Loading…
Cancel
Save