> I've been reading the boost serialization tutorial, and studying the
> demo.cpp. My struct that I want to serialize has a class from crypto++
> (the class is ECDSA<ECP, SHA1>::PublicKey). Exactly, my struct is:
>
> struct certificate_info
> {
>        int id;
>        ECDSA<ECP, SHA1>::PublicKey publicKey;
>        int id_AC;
> };
>
> Then, I would have to change the class ECDSA<ECP, SHA1>::PublicKey
> from crypto++ to add "friend class boost::serialization::access" and
> serialize template and to do the same in my struct, wouldn't I?

First off... if you need to interoperate with independent
implementations of your scheme, I strongly recommend ASN.1 instead.
That's more up-front effort but will be much easier in terms of
getting multiple independent compatible implementations.

That said, if you only need to be consistent with your own stuff,
boost serialization is probably easier. And there's no need to modify
your structure or crypto++. You can use the non-intrusive model they
show in their docs, and split the free functions so that you can lean
on crypto++'s built-in DER encoding of the keys. So create a load,
save and serialize function as shown in the docs (where the serialize
function only calls split_free()) and in your save(), call DEREncode()
on the public key object with the result going into a string sink
piped through a Base64 filter. In the load, call BERDecode() on the
public key object with the source going through a Base64 filter. It
should be about 30 lines of code total for the three methods with the
struct you describe.

Non-intrusive version of serialization:
http://www.boost.org/doc/libs/1_41_0/libs/serialization/doc/tutorial.html#nonintrusiveversion

Splitting "free functions" into save/load:
http://www.boost.org/doc/libs/1_41_0/libs/serialization/doc/serialization.html#splittingfreefunctions

HTH,

Geoff

-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.

Reply via email to