mr_keychain 0.1.0 → 0.1.1

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.
data/Gemfile CHANGED
@@ -6,5 +6,5 @@ group :development do
6
6
  gem "bluecloth", "~> 2.0.0"
7
7
  gem "bundler", "~> 1.0.0"
8
8
  gem "jeweler", "~> 1.5.2"
9
- gem "rcov", ">= 0"
9
+ # gem "rcov", ">= 0"
10
10
  end
@@ -9,7 +9,6 @@ GEM
9
9
  git (>= 1.2.5)
10
10
  rake
11
11
  rake (0.8.7)
12
- rcov (0.9.9)
13
12
  rspec (2.4.0)
14
13
  rspec-core (~> 2.4.0)
15
14
  rspec-expectations (~> 2.4.0)
@@ -27,6 +26,5 @@ DEPENDENCIES
27
26
  bluecloth (~> 2.0.0)
28
27
  bundler (~> 1.0.0)
29
28
  jeweler (~> 1.5.2)
30
- rcov
31
29
  rspec (~> 2.4.0)
32
30
  yard (~> 0.6.0)
@@ -22,10 +22,10 @@ Example Usage
22
22
  # add some search criteria, you need at least one, options are listed
23
23
  # in the keychain services reference 'Attribute Item Keys and Values'
24
24
  # section (link above)
25
- item.attributes.merge!({
25
+ item.attributes.merge!(
26
26
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
27
27
  KSecAttrServer => 'github.com'
28
- })
28
+ )
29
29
 
30
30
  # work with the entry if it exists
31
31
  if item.exists?
@@ -41,13 +41,19 @@ Example Usage
41
41
 
42
42
  # change the user name and save to the keychain
43
43
  # note how you do not need authorization to change the user name
44
- item.update!({ KSecAttrAccount => 'test' })
44
+ item.update!( KSecAttrAccount => 'test' )
45
45
  puts item.metadata[KSecAttrAccount]
46
46
 
47
47
  else
48
48
  puts 'No such item exists, maybe you need different criteria?'
49
49
  end
50
50
 
51
+ TODO
52
+ ====
53
+
54
+ - Make the simple cases simpler
55
+ - Allow more succinct names for constants and guess the actual values
56
+
51
57
  Contributing to keychain
52
58
  ========================
53
59
 
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.homepage = "http://github.com/ferrous26/keychain"
16
16
  gem.license = "MIT"
17
17
  gem.summary = %Q{Example code of how to use the Mac OS X keychain in MacRuby}
18
- gem.description = %Q{Uses APIs new in Snow Leopard to create, read, and update keychain entries}
18
+ gem.description = %Q{Takes advantage of MacRuby and uses APIs new in Snow Leopard to create, read, and update keychain entries}
19
19
  gem.email = "marada@uwaterloo.ca"
20
20
  gem.authors = ["Mark Rada"]
21
21
  end
@@ -27,10 +27,10 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
27
27
  spec.pattern = FileList['spec/**/*_spec.rb']
28
28
  end
29
29
 
30
- RSpec::Core::RakeTask.new(:rcov) do |spec|
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.rcov = true
33
- end
30
+ # RSpec::Core::RakeTask.new(:rcov) do |spec|
31
+ # spec.pattern = 'spec/**/*_spec.rb'
32
+ # spec.rcov = true
33
+ # end
34
34
 
35
35
  task :default => :spec
36
36
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -19,7 +19,6 @@ module Keychain
19
19
  #
20
20
  # In order to be secure, this class will NEVER cache a password; any time
21
21
  # that you change a password, it will be written to the keychain immeadiately.
22
-
23
22
  class Item
24
23
 
25
24
  # @return [Hash]
@@ -39,9 +38,9 @@ class Item
39
38
  # to the item you wish to work with, but you can add or remove attributes
40
39
  # via accessors as well.
41
40
  # @param [Hash] attributes
42
- def initialize attributes = nil
41
+ def initialize attributes = {}
43
42
  @attributes = { KSecClass => KSecClassInternetPassword }
44
- @attributes.merge! attributes if attributes
43
+ @attributes.merge! attributes
45
44
  end
46
45
 
47
46
  # @note This method asks only for the metadata and doesn't need authorization
@@ -50,10 +49,10 @@ class Item
50
49
  # @return [true,false]
51
50
  def exists?
52
51
  result = Pointer.new :id
53
- search = @attributes.merge({
52
+ search = @attributes.merge(
54
53
  KSecMatchLimit => KSecMatchLimitOne,
55
54
  KSecReturnAttributes => true
56
- })
55
+ )
57
56
 
58
57
  case (error_code = SecItemCopyMatching(search, result))
59
58
  when ErrSecSuccess then
@@ -76,14 +75,14 @@ class Item
76
75
  # @return [String] UTF8 encoded password string
77
76
  def password
78
77
  result = Pointer.new :id
79
- search = @attributes.merge({
78
+ search = @attributes.merge(
80
79
  KSecMatchLimit => KSecMatchLimitOne,
81
80
  KSecReturnData => true
82
- })
81
+ )
83
82
 
84
83
  case (error_code = SecItemCopyMatching(search, result))
85
84
  when ErrSecSuccess then
86
- NSString.alloc.initWithData result[0], encoding:NSUTF8StringEncoding
85
+ result[0].to_str
87
86
  else
88
87
  message = SecCopyErrorMessageString(error_code, nil)
89
88
  raise KeychainException, "Error getting password: #{message}"
@@ -97,13 +96,11 @@ class Item
97
96
  # @param [String] new_password a UTF-8 encoded string
98
97
  # @return [String] the saved password
99
98
  def password= new_password
100
- password_data = {
101
- KSecValueData => new_password.dataUsingEncoding(NSUTF8StringEncoding)
102
- }
99
+ password_data = { KSecValueData => new_password.to_data }
103
100
  if exists?
104
101
  error_code = SecItemUpdate( @attributes, password_data )
105
102
  else
106
- error_code = SecItemAdd( @attributes.merge password_data, nil )
103
+ error_code = SecItemAdd( @attributes.merge(password_data), nil )
107
104
  end
108
105
 
109
106
  case error_code
@@ -126,7 +123,7 @@ class Item
126
123
  # @return [Hash] attributes
127
124
  def update! new_attributes
128
125
  result = Pointer.new :id
129
- query = @attributes.merge({ KSecMatchLimit => KSecMatchLimitOne })
126
+ query = @attributes.merge( KSecMatchLimit => KSecMatchLimitOne )
130
127
 
131
128
  case (error_code = SecItemUpdate(query, new_attributes))
132
129
  when ErrSecSuccess then
@@ -143,10 +140,10 @@ class Item
143
140
  # @return [Hash]
144
141
  def metadata
145
142
  result = Pointer.new :id
146
- search = @attributes.merge({
143
+ search = @attributes.merge(
147
144
  KSecMatchLimit => KSecMatchLimitOne,
148
145
  KSecReturnAttributes => true
149
- })
146
+ )
150
147
 
151
148
  case (error_code = SecItemCopyMatching(search, result))
152
149
  when ErrSecSuccess then
@@ -28,7 +28,7 @@ describe 'Keychain' do
28
28
  end
29
29
 
30
30
  it 'should allow the class to be overriden' do
31
- @item = Keychain::Item.new({ KSecClass => 'different' })
31
+ @item = Keychain::Item.new( KSecClass => 'different' )
32
32
  @item.attributes[KSecClass].should == 'different'
33
33
  end
34
34
  end
@@ -36,18 +36,18 @@ describe 'Keychain' do
36
36
 
37
37
  describe '#exists?' do
38
38
  it 'returns false if the item does not exist' do
39
- @item.attributes.merge!({
39
+ @item.attributes.merge!(
40
40
  KSecAttrProtocol => KSecAttrProtocolIRCS,
41
41
  KSecAttrServer => 'github.com'
42
- })
42
+ )
43
43
  @item.exists?.should == false
44
44
  end
45
45
 
46
46
  it 'returns true if the item exists' do
47
- @item.attributes.merge!({
47
+ @item.attributes.merge!(
48
48
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
49
49
  KSecAttrServer => 'github.com'
50
- })
50
+ )
51
51
  @item.exists?.should == true
52
52
  end
53
53
 
@@ -60,18 +60,18 @@ describe 'Keychain' do
60
60
 
61
61
  describe '#password' do
62
62
  it 'should return a string with the password' do
63
- @item.attributes.merge!({
63
+ @item.attributes.merge!(
64
64
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
65
65
  KSecAttrServer => 'github.com'
66
- })
66
+ )
67
67
  @item.password.class.should == String
68
68
  end
69
69
 
70
70
  it 'should raise an exception if no password is found' do
71
- @item.attributes.merge!({
71
+ @item.attributes.merge!(
72
72
  KSecAttrProtocol => KSecAttrProtocolIRCS,
73
73
  KSecAttrServer => 'github.com'
74
- })
74
+ )
75
75
  expect { @item.password }.to raise_exception(Keychain::KeychainException)
76
76
  end
77
77
  end
@@ -79,27 +79,27 @@ describe 'Keychain' do
79
79
 
80
80
  describe '#metadata' do
81
81
  it 'should return a hash' do
82
- @item.attributes.merge!({
82
+ @item.attributes.merge!(
83
83
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
84
84
  KSecAttrServer => 'github.com'
85
- })
85
+ )
86
86
  @item.metadata.class.should == Hash
87
87
  end
88
88
 
89
89
  it 'should raise an exception if nothing is found' do
90
- @item.attributes.merge!({
90
+ @item.attributes.merge!(
91
91
  KSecAttrProtocol => KSecAttrProtocolIRCS,
92
92
  KSecAttrServer => 'github.com'
93
- })
93
+ )
94
94
  expect { @item.metadata }.to raise_exception(Keychain::KeychainException)
95
95
  end
96
96
 
97
97
  # this assumes the keychain item has more metadata
98
98
  it 'should not overwrite @attributes' do
99
- @item.attributes.merge!({
99
+ @item.attributes.merge!(
100
100
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
101
101
  KSecAttrServer => 'github.com'
102
- })
102
+ )
103
103
  metadata = @item.metadata
104
104
  @item.attributes.should_not == metadata
105
105
  end
@@ -108,27 +108,27 @@ describe 'Keychain' do
108
108
 
109
109
  describe '#metadata!' do
110
110
  it 'should return a hash' do
111
- @item.attributes.merge!({
111
+ @item.attributes.merge!(
112
112
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
113
113
  KSecAttrServer => 'github.com'
114
- })
114
+ )
115
115
  @item.metadata.class.should == Hash
116
116
  end
117
117
 
118
118
  it 'should raise an exception if nothing is found' do
119
- @item.attributes.merge!({
119
+ @item.attributes.merge!(
120
120
  KSecAttrProtocol => KSecAttrProtocolIRCS,
121
121
  KSecAttrServer => 'github.com'
122
- })
122
+ )
123
123
  expect { @item.metadata }.to raise_exception(Keychain::KeychainException)
124
124
  end
125
125
 
126
126
  # this assumes the keychain item has more metadata
127
127
  it 'should overwrite @attributes' do
128
- @item.attributes.merge!({
128
+ @item.attributes.merge!(
129
129
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
130
130
  KSecAttrServer => 'github.com'
131
- })
131
+ )
132
132
  metadata = @item.metadata!
133
133
  @item.attributes.should == metadata
134
134
  end
@@ -154,10 +154,10 @@ describe 'Keychain' do
154
154
 
155
155
  # describe '#password=' do
156
156
  # before do
157
- # @item.attributes.merge!({
157
+ # @item.attributes.merge!(
158
158
  # KSecAttrProtocol => KSecAttrProtocolHTTPS,
159
159
  # KSecAttrServer => 'github.com'
160
- # })
160
+ # )
161
161
  # end
162
162
 
163
163
  # it 'should return the updated password' do
@@ -169,9 +169,9 @@ describe 'Keychain' do
169
169
  # end
170
170
 
171
171
  # it 'should create entries if they do not exsit' do
172
- # @item.attributes.merge!({
172
+ # @item.attributes.merge!(
173
173
  # KSecAttrAccount => 'test'
174
- # })
174
+ # )
175
175
  # @item.password = 'another test'
176
176
  # @item.exists?.should == true
177
177
  # end
@@ -184,41 +184,41 @@ describe 'Keychain' do
184
184
 
185
185
  describe '#update!' do
186
186
  it 'should update fields given in the persistent keychain' do
187
- @item.attributes.merge!({
187
+ @item.attributes.merge!(
188
188
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
189
189
  KSecAttrServer => 'github.com'
190
- })
190
+ )
191
191
  @item.update!({ KSecAttrComment => 'test' })
192
192
  @item.metadata[KSecAttrComment].should == 'test'
193
193
  end
194
194
 
195
195
  it 'should raise an exception for non-existant items' do
196
- @item.attributes.merge!({
196
+ @item.attributes.merge!(
197
197
  KSecAttrProtocol => KSecAttrProtocolIRCS,
198
198
  KSecAttrServer => 'github.com'
199
- })
199
+ )
200
200
  expect {
201
- @item.update!({ KSecAttrComment => 'different test' })
201
+ @item.update!( KSecAttrComment => 'different test' )
202
202
  }.to raise_exception(Keychain::KeychainException)
203
203
  end
204
204
 
205
205
  it 'should update @attributes' do
206
- @item.attributes.merge!({
206
+ @item.attributes.merge!(
207
207
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
208
208
  KSecAttrServer => 'github.com'
209
- })
209
+ )
210
210
  @item.update!({ KSecAttrComment => 'toast' })
211
211
  @item.attributes[KSecAttrComment].should == 'toast'
212
212
  end
213
213
 
214
214
  it 'should return the metadata of the keychain item' do
215
- @item.attributes.merge!({
215
+ @item.attributes.merge!(
216
216
  KSecAttrProtocol => KSecAttrProtocolHTTPS,
217
217
  KSecAttrServer => 'github.com'
218
- })
219
- @item.update!({
218
+ )
219
+ @item.update!(
220
220
  KSecAttrComment => 'bread'
221
- })[KSecAttrComment].should == 'bread'
221
+ )[KSecAttrComment].should == 'bread'
222
222
  end
223
223
  end
224
224
 
metadata CHANGED
@@ -1,120 +1,106 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mr_keychain
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Mark Rada
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-05 00:00:00 -05:00
12
+ date: 2011-03-01 00:00:00 -05:00
18
13
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
21
16
  name: rspec
22
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
23
18
  none: false
24
- requirements:
19
+ requirements:
25
20
  - - ~>
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 4
30
- - 0
21
+ - !ruby/object:Gem::Version
31
22
  version: 2.4.0
32
23
  type: :development
33
24
  prerelease: false
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 2.4.0
31
+ - !ruby/object:Gem::Dependency
36
32
  name: yard
37
- requirement: &id002 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
38
34
  none: false
39
- requirements:
35
+ requirements:
40
36
  - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
- - 6
45
- - 0
37
+ - !ruby/object:Gem::Version
46
38
  version: 0.6.0
47
39
  type: :development
48
40
  prerelease: false
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.6.0
47
+ - !ruby/object:Gem::Dependency
51
48
  name: bluecloth
52
- requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
51
+ requirements:
55
52
  - - ~>
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 2
59
- - 0
60
- - 0
53
+ - !ruby/object:Gem::Version
61
54
  version: 2.0.0
62
55
  type: :development
63
56
  prerelease: false
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 2.0.0
63
+ - !ruby/object:Gem::Dependency
66
64
  name: bundler
67
- requirement: &id004 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
68
66
  none: false
69
- requirements:
67
+ requirements:
70
68
  - - ~>
71
- - !ruby/object:Gem::Version
72
- segments:
73
- - 1
74
- - 0
75
- - 0
69
+ - !ruby/object:Gem::Version
76
70
  version: 1.0.0
77
71
  type: :development
78
72
  prerelease: false
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.0.0
79
+ - !ruby/object:Gem::Dependency
81
80
  name: jeweler
82
- requirement: &id005 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
83
82
  none: false
84
- requirements:
83
+ requirements:
85
84
  - - ~>
86
- - !ruby/object:Gem::Version
87
- segments:
88
- - 1
89
- - 5
90
- - 2
85
+ - !ruby/object:Gem::Version
91
86
  version: 1.5.2
92
87
  type: :development
93
88
  prerelease: false
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
- name: rcov
97
- requirement: &id006 !ruby/object:Gem::Requirement
89
+ version_requirements: !ruby/object:Gem::Requirement
98
90
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
- version: "0"
105
- type: :development
106
- prerelease: false
107
- version_requirements: *id006
108
- description: Uses APIs new in Snow Leopard to create, read, and update keychain entries
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 1.5.2
95
+ description: Takes advantage of MacRuby and uses APIs new in Snow Leopard to create,
96
+ read, and update keychain entries
109
97
  email: marada@uwaterloo.ca
110
98
  executables: []
111
-
112
99
  extensions: []
113
-
114
- extra_rdoc_files:
100
+ extra_rdoc_files:
115
101
  - LICENSE.txt
116
102
  - README.markdown
117
- files:
103
+ files:
118
104
  - .document
119
105
  - .rspec
120
106
  - .rvmrc
@@ -130,37 +116,30 @@ files:
130
116
  - spec/spec_helper.rb
131
117
  has_rdoc: true
132
118
  homepage: http://github.com/ferrous26/keychain
133
- licenses:
119
+ licenses:
134
120
  - MIT
135
121
  post_install_message:
136
122
  rdoc_options: []
137
-
138
- require_paths:
123
+ require_paths:
139
124
  - lib
140
- required_ruby_version: !ruby/object:Gem::Requirement
125
+ required_ruby_version: !ruby/object:Gem::Requirement
141
126
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- hash: -1899776903697949187
146
- segments:
147
- - 0
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
148
130
  version: "0"
149
- required_rubygems_version: !ruby/object:Gem::Requirement
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
132
  none: false
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- segments:
155
- - 0
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
156
136
  version: "0"
157
137
  requirements: []
158
-
159
138
  rubyforge_project:
160
- rubygems_version: 1.3.7
139
+ rubygems_version: 1.4.2
161
140
  signing_key:
162
141
  specification_version: 3
163
142
  summary: Example code of how to use the Mac OS X keychain in MacRuby
164
- test_files:
143
+ test_files:
165
144
  - spec/keychain_spec.rb
166
145
  - spec/spec_helper.rb