pointless OpenSSL object creation on every event?
Closed this issue · 7 comments
AFAICT the OpenSSL object creation in encryption_algorithm
register
method in an ivar and reused in the OpenSSL::HMAC.digest
calls...
Is there something I am missing?
I will probably add a refactoring for this for elastic/logstash/issues/4419 in #10
thoughts @ph @jordansissel ?
Well I agree it will never change during the plugin lifetime.
Pointless may be the wrong word here, but I agree it's in the wrong place - as you propose, it should probably be an ivar initialized once in register
.
Some digest APIs allow streaming chunks into it, and just on a hunch I tried to see if reusing a digest instance would cause different values, and it's always the same, so it is safe to reuse. +1 on ivar.
>> digest = OpenSSL::Digest::SHA256.new
>> OpenSSL::HMAC.hexdigest(digest, "hello", "world")
=> "f1ac9702eb5faf23ca291a4dc46deddeee2a78ccdaf0a412bed7714cfffb1cc4"
>> OpenSSL::HMAC.hexdigest(digest, "hello", "world")
=> "f1ac9702eb5faf23ca291a4dc46deddeee2a78ccdaf0a412bed7714cfffb1cc4"
@method
never changes so encryption_algorithm
will always initialize and yield the same object for sure but I am wondering if there might be something related to state side effected between calls ...
@jordansissel yeah thanks. will refactor.
refactor committed in #10
closing per #10