Giter Site home page Giter Site logo

Comments (7)

DaHoopster avatar DaHoopster commented on June 25, 2024 1

Actually I made it work via pure Ruby by subclassing OpenSSL::Digest. The trick is also call super in the constructor. Thanks!

from sha3.

johanns avatar johanns commented on June 25, 2024

But it looks like Ruby 2.5.1 doesn't work with this library.

Is there an error message you're receiving when trying to use it? What happens if you run the following code from IRB or Pry (assuming your already installed the gem gem install sha3)?

require 'sha3'
SHA3::Digest::SHA224.new()

Please post any error message(s), and operating system information (sample code would be great too).

Any thoughts on how I can combine the two?

I'd love to help, but I'm unsure how you're trying to "combine" them. Please provide more context.

from sha3.

DaHoopster avatar DaHoopster commented on June 25, 2024

Sorry, pardon the ambiguities, here are the details 😄

I was attempting to do the below:

require 'sha3'
require 'openssl'

p_key = OpenSSL::PKey::EC.new('secp256k1').generate_key
p_key.sign(SHA3::Digest.new(:sha256), 'a_super_secret')

Because sha3 isn't a subclass of OpenSSL::Digest, I got the follow error:

TypeError:
       wrong argument type SHA3::Digest (expected OpenSSL/Digest)

And I am stuck ...

from sha3.

johanns avatar johanns commented on June 25, 2024

That's helpful, but unfortunately I don't have a solution for your particular use case. I suppose it would be possible to change the base class to OpenSSL::Digest from Digest::Class (which is also the parent class for OpenSSL::Digest), but that doesn't like a good idea because the actual SHA3 implementation isn't part of OpenSSL library.

Assuming that you must use SHA3, you can either fork this project, and change the base class to OpenSSL::Digest (see below), or create a new OpenSSL::Digest subclass that proxies data to SHA3::Digest.

cSHA3Digest = rb_define_class_under(mSHA3, "Digest", rb_path2class("Digest::Class"));

from sha3.

DaHoopster avatar DaHoopster commented on June 25, 2024

Thanks @johanns , I will try forking the project

from sha3.

DaHoopster avatar DaHoopster commented on June 25, 2024

Hmm still no good. It looks like the error message comes from the C extension within ruby's openssl code. I read it on stackoverflow (lost the link) that in order to add a custom digest, a C struct needs to be used as the context, like this line: https://github.com/ruby/openssl/blob/master/ext/openssl/ossl_digest.h#L16

The type error comes from this line: https://github.com/ruby/openssl/blob/fdcda971a26895ea5c5015a90671ee73039d55e8/ext/openssl/ossl.h#L59

I am not good with C tho ...

from sha3.

katpadi avatar katpadi commented on June 25, 2024

Hi @DaHoopster,

How were you able to make it work? Did you actually monkeypatch the SHA3::Digest class? Can you point me to the right direction? Thanks.

from sha3.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.