esteid 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0abe7a1c10742a52b917a524eef713eabe3b6a6
4
- data.tar.gz: 1a580a990003b0195f8ef151114a92a6bb2498bb
3
+ metadata.gz: 672562dea02e6e9b88e7033f37859c7b2baf2473
4
+ data.tar.gz: 857f4eb96f0006232b95004f13f4ba31f4c41049
5
5
  SHA512:
6
- metadata.gz: a0b8834f0aa7a5d776a5290f79901db90a58282c472d85d542c4547ebf0af0bae65b69a2619863cdab17c4d93c58eefd7c639c80a8c3be8dd8478b6846281d43
7
- data.tar.gz: 2b810d898c817eadb7f2df03a44e7d68cea642cb4d8c3f692ad45be4e3276a7edcb557aa51fdac8644251d447371beaf6ab82c0322eb099e8b86610eae9992a1
6
+ metadata.gz: 241aebde16323d30d412426fde0c75edd99c54183c2120dd6eb9eef8b0e1737e341d54f0c7861554fc2eb6df4f39a25c1d439cf181b85cee1553772ab87e815f
7
+ data.tar.gz: ac572eaa3b41dcfef513af065a2a986a3fa7a27d33bc69d7c81b8d7fe00955fd914757595ebfa1709643b89704f7b7594037d7d590efee8b115769f4f5fd5ef2
@@ -3,7 +3,7 @@ module EstEID
3
3
  attr_reader :eid_cert
4
4
 
5
5
  def initialize(request)
6
- @eid_cert = request.headers["HTTP_X_ESTEID_CERT"]
6
+ @eid_cert = request.headers[EstEID.config.certificate_header]
7
7
  end
8
8
 
9
9
  def valid?
@@ -17,16 +17,29 @@ module EstEID
17
17
 
18
18
  def first_name
19
19
  return unless valid?
20
- data_hash["GN"]
20
+ normalize(data_hash["GN"])
21
21
  end
22
22
 
23
23
  def last_name
24
24
  return unless valid?
25
- data_hash["SN"]
25
+ normalize(data_hash["SN"])
26
26
  end
27
27
 
28
28
  private
29
29
 
30
+ def normalize(str)
31
+ result = str.gsub(/\\x([\da-fA-F]{2})/) { |m| [m].pack('H*') }
32
+
33
+ if str =~ /\\x00/
34
+ # UCS-2 encoding
35
+ result.force_encoding('utf-16be').encode!('utf-8')
36
+ else
37
+ result.force_encoding('UTF-8')
38
+ end
39
+
40
+ result
41
+ end
42
+
30
43
  def data_hash
31
44
  @data_hash ||= parse_header
32
45
  end
@@ -0,0 +1,19 @@
1
+ module EstEID
2
+ class << self
3
+ attr_reader :config
4
+ end
5
+
6
+ def self.configure
7
+ @config = Configuration.new
8
+ yield(@config) if block_given?
9
+ @config
10
+ end
11
+
12
+ class Configuration
13
+ attr_accessor :certificate_header
14
+
15
+ def initialize
16
+ @certificate_header = nil
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module EstEID
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esteid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Pakk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-10 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - esteid.gemspec
72
72
  - lib/esteid.rb
73
73
  - lib/esteid/authentication.rb
74
+ - lib/esteid/configuration.rb
74
75
  - lib/esteid/version.rb
75
76
  homepage: https://github.com/deskrock/esteid
76
77
  licenses: