sshkey 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sshkey.rb CHANGED
@@ -7,8 +7,8 @@ class SSHKey
7
7
  SSH_TYPES = {"rsa" => "ssh-rsa", "dsa" => "ssh-dss"}
8
8
  SSH_CONVERSION = {"rsa" => ["e", "n"], "dsa" => ["p", "q", "g", "pub_key"]}
9
9
 
10
- attr_reader :key_object, :comment, :type
11
- attr_accessor :passphrase
10
+ attr_reader :key_object, :type
11
+ attr_accessor :passphrase, :comment
12
12
 
13
13
  class << self
14
14
  # Generate a new keypair and return an SSHKey object
@@ -109,7 +109,7 @@ class SSHKey
109
109
  end
110
110
 
111
111
  def decoded_key(key)
112
- Base64.decode64(key.chomp.gsub(/ssh-[dr]s[as] /, ''))
112
+ Base64.decode64(key.gsub(/^(ssh-[dr]s[as]\s+)|(\s+.+\@.+)|\n/, ''))
113
113
  end
114
114
 
115
115
  def fingerprint_regex
@@ -188,6 +188,11 @@ class SSHKey
188
188
  Digest::SHA1.hexdigest(ssh_public_key_conversion).gsub(/(.{2})(?=.)/, '\1:\2')
189
189
  end
190
190
 
191
+ # Determine the length (bits) of the key as an integer
192
+ def bits
193
+ key_object.to_text.match(/Private-Key:\s\((\d*)\sbit\)/)[1].to_i
194
+ end
195
+
191
196
  private
192
197
 
193
198
  # SSH Public Key Conversion
@@ -1,3 +1,3 @@
1
1
  class SSHKey
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  end
data/test/sshkey_test.rb CHANGED
@@ -204,14 +204,14 @@ EOF
204
204
  assert_equal KEY1_SHA1_FINGERPRINT, @key1.sha1_fingerprint
205
205
  assert_equal KEY2_SHA1_FINGERPRINT, @key2.sha1_fingerprint
206
206
  assert_equal KEY3_SHA1_FINGERPRINT, @key3.sha1_fingerprint
207
-
207
+
208
208
  assert_equal KEY1_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PRIVATE_KEY1)
209
209
  assert_equal KEY1_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PUBLIC_KEY1)
210
210
  assert_equal KEY2_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PRIVATE_KEY2)
211
211
  assert_equal KEY2_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PUBLIC_KEY2)
212
212
  assert_equal KEY3_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PRIVATE_KEY3)
213
213
  assert_equal KEY3_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PUBLIC_KEY3)
214
-
214
+
215
215
  assert_equal KEY1_SHA1_FINGERPRINT, SSHKey.sha1_fingerprint(SSH_PRIVATE_KEY1)
216
216
  assert_equal KEY1_SHA1_FINGERPRINT, SSHKey.sha1_fingerprint(SSH_PUBLIC_KEY1)
217
217
  assert_equal KEY2_SHA1_FINGERPRINT, SSHKey.sha1_fingerprint(SSH_PRIVATE_KEY2)
@@ -220,6 +220,13 @@ EOF
220
220
  assert_equal KEY3_SHA1_FINGERPRINT, SSHKey.sha1_fingerprint(SSH_PUBLIC_KEY3)
221
221
  end
222
222
 
223
+ def test_bits
224
+ assert_equal 2048, @key1.bits
225
+ assert_equal 2048, @key2.bits
226
+ assert_equal 1024, @key3.bits
227
+ assert_equal 512, SSHKey.generate(bits: 512).bits
228
+ end
229
+
223
230
  def test_to_byte_array
224
231
  ba1 = @key1.send(:to_byte_array, 35)
225
232
  ba2 = @key1.send(:to_byte_array, 65537)
metadata CHANGED
@@ -1,34 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshkey
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.3.2
4
+ version: 1.3.3
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Miller
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- version_requirements: !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
17
18
  requirements:
18
- - - ">="
19
+ - - ! '>='
19
20
  - !ruby/object:Gem::Version
20
- version: !binary |-
21
- MA==
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
22
25
  none: false
23
- requirement: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - ">="
27
+ - - ! '>='
26
28
  - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
29
- none: false
30
- prerelease: false
31
- type: :development
29
+ version: '0'
32
30
  description: Generate private/public SSH keypairs using pure Ruby
33
31
  email:
34
32
  - bensie@gmail.com
@@ -36,8 +34,8 @@ executables: []
36
34
  extensions: []
37
35
  extra_rdoc_files: []
38
36
  files:
39
- - ".gitignore"
40
- - ".travis.yml"
37
+ - .gitignore
38
+ - .travis.yml
41
39
  - Gemfile
42
40
  - LICENSE
43
41
  - README.md
@@ -48,28 +46,26 @@ files:
48
46
  - test/sshkey_test.rb
49
47
  homepage: https://github.com/bensie/sshkey
50
48
  licenses: []
51
- post_install_message:
49
+ post_install_message:
52
50
  rdoc_options: []
53
51
  require_paths:
54
52
  - lib
55
53
  required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
56
55
  requirements:
57
- - - ">="
56
+ - - ! '>='
58
57
  - !ruby/object:Gem::Version
59
- version: !binary |-
60
- MA==
61
- none: false
58
+ version: '0'
62
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
63
61
  requirements:
64
- - - ">="
62
+ - - ! '>='
65
63
  - !ruby/object:Gem::Version
66
- version: !binary |-
67
- MA==
68
- none: false
64
+ version: '0'
69
65
  requirements: []
70
66
  rubyforge_project: sshkey
71
- rubygems_version: 1.8.24
72
- signing_key:
67
+ rubygems_version: 1.8.23
68
+ signing_key:
73
69
  specification_version: 3
74
70
  summary: SSH private/public key generator in Ruby
75
71
  test_files: