[Botan-devel] botan-devel Digest, Vol 50, Issue 2

Z. S. O. tiredashell at gmail.com
Mon Mar 9 16:05:25 EDT 2009


Thank you so much Falko! My code works perfectly now.

On Mon, Mar 9, 2009 at 10:44 AM, Falko Strenzke <strenzke at flexsecure.de>wrote:

> Hi,
>
> I only took a glance at your code, but one thing sure is not a good
> idea. Thats calling get() on an auto_ptr to store it's pointer value
> somewhere else. As far as I know, then it can happen that the compiler
> destroys the auto_ptr before it goes out of scope (since he understands
> that you don't use it anymore), invalidating the object you got a
> pointer to by calling get(). To verify that, try something like
> std::cout << loadedPrivateKey.get() << std::endl;
> at the very end of the function. That should prevent the auto_ptr from
> being destructed too soon.
>
> But to use the auto_ptr correctly, use release() instead of get(). Then
> the auto_ptr is assigned NULL, and will never call the the destructor of
> it's former pointee, which is the object you want to use.
>
> Regards,
> Falko
>
> > Message: 1
> > Date: Sat, 7 Mar 2009 20:16:16 -0500
> > From: "Z. S. O." <tiredashell at gmail.com>
> > Subject: [Botan-devel] Creating a class for signing data
> > To: Botan development list <botan-devel at randombit.net>
> > Message-ID:
> >       <d6bdc39c0903071716v7b2dfec0x14175111c732c5cf at mail.gmail.com>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > Sorry once again for all my questions; I only resort to this list when
> I've
> > tried everything else.
> > I'm trying to make classes that encapsulate various things in Botan. The
> one
> > below is meant to create digital signatures. You'll notice that I try my
> > best to optimize performance by making rng a global variable and signer a
> > class data member, so I don't have to keep recreating them locally. The
> > problem is that when I try to perform this->signer->sign_message(), it
> > creates a segmentation fault.
> >
> > I admit I'm still an amateur at C++, so if I could get an explanation
> about
> > what I'm doing wrong I would really appreciate it.
> >
> > class MySigner
> > {
> >   public:
> >     MySigner (string privateKey)
> >     {
> > DataSource_Memory key_src(privateKey);
> > auto_ptr<PKCS8_PrivateKey> loadedPrivateKey(PKCS8::load_key(key_src,
> rng));
> > RSA_PrivateKey* rsaPrivateKey =
> > dynamic_cast<RSA_PrivateKey*>(loadedPrivateKey.get());
> > PK_Signing_Key* key = dynamic_cast<PK_Signing_Key*>(rsaPrivateKey);
> > this->signer = get_pk_signer(*key, "EMSA4(SHA-1)");
> >     }
> >
> >     string Sign (string message)
> >     {
> > byte *msg = (unsigned char*) message.c_str();
> > return b64_encode(this->signer->sign_message(msg, sizeof(msg), rng));
> >     }
> >   private:
> >     PK_Signer* signer;
> > };
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: <
> http://lists.randombit.net/pipermail/botan-devel/attachments/20090307/e1a343b3/attachment.html
> >
> >
> > ------------------------------
> >
> > _______________________________________________
> > botan-devel mailing list
> > botan-devel at randombit.net
> > http://lists.randombit.net/mailman/listinfo/botan-devel
> >
> >
> > End of botan-devel Digest, Vol 50, Issue 2
> > ******************************************
> >
>
>
> --
>
> Dipl.-Phys.
> Falko Strenzke
> FlexSecure GmbH
> Industriestr. 12
> D - 64297 Darmstadt
> Tel.: +49 (0) 6151 501 23-14
> Fax:  +49 (0) 6151 501 23-19
> E-Mail: strenzke at flexsecure.de
> Internet: www.flexsecure.de
>
> Geschäftsführer:
> Erwin Stallenberger, Markus Ruppert
>
> Amtsgericht Darmstadt
> HRB 8036
> Umsatzsteuernummer:
> DE 214745269
>
>
>
>
>
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://lists.randombit.net/mailman/listinfo/botan-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20090309/fb4ff364/attachment.html>


More information about the botan-devel mailing list