Sha256: a3525f5984fb6de74049be45d655dd0f500c9fede00770794feaa9562f268982

Contents?: true

Size: 685 Bytes

Versions: 3

Compression:

Stored size: 685 Bytes

Contents

module PolyPseudo
  class Identity
    include PolyPseudo::PseudoId

    # @param [PolyPseudo::Key] key
    def decrypt(key)
      PolyPseudo.init!

      public_key = key.ec.public_key

      raise "Invalid key for decryption" if point_3 != public_key

      private_key = key.ec.private_key

      identity_point = point_1
          .mul(private_key)
          .invert!
          .add(point_2)
          .make_affine!

      @identity = Util.oaep_decode(identity_point.x.to_s(2)).slice(3, 10).force_encoding("UTF-8").strip
    end

    def identity
      @identity || raise('Identity not decrypted yet. call .decrypt first')
    end

    alias_method :pseudo_id, :identity
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
poly_pseudo-0.1.3 lib/poly_pseudo/identity.rb
poly_pseudo-0.1.2 lib/poly_pseudo/identity.rb
poly_pseudo-0.1.1 lib/poly_pseudo/identity.rb