poly_pseudo 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f73daa683f2a0b467bbc8ae993c69ef723ef310ce7ebecbfc0d3eff8df314fdf
4
- data.tar.gz: 957b1b0be8958587deee6cbc0a5047f8ffc71f272946ec305744540bef4f26b8
3
+ metadata.gz: 4d249e4591da0413414ed62b3acc5d092ba82abe6e680a285510ff4e32bbbdab
4
+ data.tar.gz: c879e52bd77278d75f175d3be05f12657ed8ac1154d250d80d6c1cb6c5c71b0a
5
5
  SHA512:
6
- metadata.gz: 835eaecef1864eaee59bd5bdb7950775d29eeecad180c4e5381bc295b84c80d0440727d5ee187108ecb669415ebcda4107daf4f0b98b5ee89ad93e96ea83fbb5
7
- data.tar.gz: a7ab8150b864b1f5e9484ef6bfc3f7dabd2116c8de7ffbe86c6ba327e5271a851f0b3d8f011642f22bec543acfd2d76562c2396af81e4fd93fb74332eab65ffe
6
+ metadata.gz: c705f80284dde04eed0d3c965b2162f47faafd4bd329ddf68cb2878d5cfb270071eec8de6cc343ec793c48e23594017622a92163ba0b438431cab4c264515a67
7
+ data.tar.gz: f03bda21cccb82709652f94bb384467103cf6dc513df5c06aee72b4055fc2e4865c1e1d3c861da2eeb39175aea2116948b4b58c8eb93c578294861ff4891861d
@@ -2,6 +2,21 @@ module PolyPseudo
2
2
  class Identity
3
3
  include PolyPseudo::PseudoId
4
4
 
5
+ def self.from_asn1(asn1)
6
+ attributes = {}
7
+ attributes["Type"] = asn1.value[0].value.to_s
8
+ attributes["SchemaVersion"] = asn1.value[1].value.to_i
9
+ attributes["SchemaKeyVersion"] = asn1.value[2].value.to_i
10
+ attributes["Creator"] = asn1.value[3].value.to_s
11
+ attributes["Recipient"] = asn1.value[4].value.to_s
12
+ attributes["RecipientKeySetVersion"] = asn1.value[5].value.to_i
13
+ attributes["Point1"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group, OpenSSL::BN.new(asn1.value[6].value[0].value, 2))
14
+ attributes["Point2"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group, OpenSSL::BN.new(asn1.value[6].value[1].value, 2))
15
+ attributes["Point3"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group, OpenSSL::BN.new(asn1.value[6].value[2].value, 2))
16
+
17
+ new(attributes)
18
+ end
19
+
5
20
  # @param [PolyPseudo::Key] key
6
21
  def decrypt(key)
7
22
  PolyPseudo.init!
@@ -1,26 +1,17 @@
1
1
  module PolyPseudo
2
2
  module PseudoId
3
3
  def self.from_asn1(encoded)
4
- attributes = {}
5
- asn1 = OpenSSL::ASN1.decode(Base64.decode64(encoded))
6
- attributes["Type"] = asn1.value[0].value.to_s
7
- attributes["SchemaVersion"] = asn1.value[1].value.to_i
8
- attributes["SchemaKeyVersion"] = asn1.value[2].value.to_i
9
- attributes["Creator"] = asn1.value[3].value.to_s
10
- attributes["Recipient"] = asn1.value[4].value.to_s
11
- attributes["RecipientKeySetVersion"] = asn1.value[5].value.to_i
12
- attributes["Point1"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group,
13
- OpenSSL::BN.new(asn1.value[6].value[0].value, 2))
14
- attributes["Point2"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group,
15
- OpenSSL::BN.new(asn1.value[6].value[1].value, 2))
16
- attributes["Point3"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group,
17
- OpenSSL::BN.new(asn1.value[6].value[2].value, 2))
4
+ asn1 = OpenSSL::ASN1.decode(Base64.decode64(encoded))
18
5
 
19
- case attributes["Type"]
6
+ case asn1.value[0].value.to_s
20
7
  when /\A.*1\.2\.1\Z/
21
- Identity.new(attributes)
8
+ Identity.from_asn1(asn1)
22
9
  when /\A.*1\.2\.2\Z/
23
- Pseudonym.new(attributes)
10
+ Pseudonym.from_asn1(asn1)
11
+ when /\A.*1\.2\.3\Z/
12
+ Identity.from_asn1(asn1.value[1].value[0])
13
+ when /\A.*1\.2\.4\Z/
14
+ Pseudonym.from_asn1(asn1.value[1].value[0])
24
15
  else
25
16
  raise "Invalid type"
26
17
  end
@@ -2,6 +2,21 @@ module PolyPseudo
2
2
  class Pseudonym
3
3
  include PolyPseudo::PseudoId
4
4
 
5
+ def self.from_asn1(asn1)
6
+ attributes = {}
7
+ attributes["Type"] = asn1.value[0].value.to_s
8
+ attributes["SchemaVersion"] = asn1.value[1].value.to_i
9
+ attributes["SchemaKeyVersion"] = asn1.value[2].value.to_i
10
+ attributes["Creator"] = asn1.value[3].value.to_s
11
+ attributes["Recipient"] = asn1.value[4].value.to_s
12
+ attributes["RecipientKeySetVersion"] = asn1.value[5].value.to_i
13
+ attributes["Point1"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group, OpenSSL::BN.new(asn1.value[7].value[0].value, 2))
14
+ attributes["Point2"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group, OpenSSL::BN.new(asn1.value[7].value[1].value, 2))
15
+ attributes["Point3"] = OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group, OpenSSL::BN.new(asn1.value[7].value[2].value, 2))
16
+
17
+ new(attributes)
18
+ end
19
+
5
20
  # @param [PolyPseudo::Key] closing_key
6
21
  def decrypt(decryption_key, closing_key)
7
22
  PolyPseudo.init!
@@ -1,3 +1,3 @@
1
1
  module PolyPseudo
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poly_pseudo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoist Claassen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-05 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler