distinguished_name 0.0.3 → 0.0.4

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.
@@ -6,15 +6,48 @@ class DistinguishedName::Transform
6
6
 
7
7
  def slashify(dn_string)
8
8
  x509_parsed_dn = parse_dn(dn_string)
9
- x509_parsed_dn.to_a.map {|piece| "/#{piece[0]}=#{piece[1]}" }.reverse.join
9
+ prefix = '/'
10
+ separator = ''
11
+ if in_slash_format?(dn_string)
12
+ big_endian(x509_parsed_dn, prefix, separator)
13
+ else
14
+ little_endian(x509_parsed_dn, prefix, separator)
15
+ end
10
16
  end
11
17
 
12
18
  def ldapify(dn_string)
13
19
  x509_parsed_dn = parse_dn(dn_string)
14
- x509_parsed_dn.to_a.map {|piece| "#{piece[0]}=#{piece[1]}" }.reverse.join(",")
20
+ prefix = ''
21
+ separator = ','
22
+ if in_ldap_format?(dn_string)
23
+ big_endian(x509_parsed_dn, prefix, separator)
24
+ else
25
+ little_endian(x509_parsed_dn, prefix, separator)
26
+ end
15
27
  end
16
28
 
17
29
  private
30
+
31
+ def big_endian(x509_parsed_dn, prefix, separator)
32
+ x509_parsed_dn.to_a.map {|piece| "#{prefix}#{piece[0]}=#{piece[1]}" }.join(separator)
33
+ end
34
+
35
+ def little_endian(x509_parsed_dn, prefix, separator)
36
+ x509_parsed_dn.to_a.map {|piece| "#{prefix}#{piece[0]}=#{piece[1]}" }.reverse.join(separator)
37
+ end
38
+
39
+ def in_slash_format?(dn_string)
40
+ !in_ldap_format?(dn_string)
41
+ end
42
+
43
+ def in_ldap_format?(dn_string)
44
+ begin
45
+ OpenSSL::X509::Name.parse_rfc2253(dn_string)
46
+ rescue OpenSSL::X509::NameError
47
+ return false
48
+ end
49
+ return true
50
+ end
18
51
 
19
52
  def parse_dn(dn_string)
20
53
  begin
@@ -1,3 +1,3 @@
1
1
  module DistinguishedName
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,2 +1,7 @@
1
1
  require 'test/unit'
2
- require_relative "../lib/distinguished_name"
2
+
3
+ if Kernel.respond_to?(:require_relative)
4
+ require_relative "../lib/distinguished_name"
5
+ else
6
+ require File.join(File.dirname(caller[0]), "../lib/distinguished_name")
7
+ end
@@ -9,7 +9,6 @@ class TransformTest < Test::Unit::TestCase
9
9
  super
10
10
  end
11
11
 
12
- =begin
13
12
  def test_ldapify_doesnt_modify_ldap_dn
14
13
  assert_equal(@ldap_dn, DistinguishedName::Transform.ldapify(@ldap_dn))
15
14
  end
@@ -17,7 +16,6 @@ class TransformTest < Test::Unit::TestCase
17
16
  def test_slashify_doesnt_modify_slash_dn
18
17
  assert_equal(@slash_dn, DistinguishedName::Transform.slashify(@slash_dn))
19
18
  end
20
- =end
21
19
 
22
20
  def test_slashify_accepts_a_comma_separated_version_and_returns_a_slash_separated_version_of_the_dn
23
21
  assert_equal(@slash_dn, DistinguishedName::Transform.slashify(@ldap_dn))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distinguished_name
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This is a gem for interacting with the string representation of distinguished names, per the RFC-1779 (http://www.ietf.org/rfc/rfc1779.txt)
15
15
  email: