password_protected_file 0.0.1 → 0.0.2
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 +4 -4
- data/lib/password_protected_file.rb +15 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22f79bd8144d4177e3864230ff65e59f256b6bd3
|
4
|
+
data.tar.gz: 91f718ca2909d063607e7a2ad90685df20cc146d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 666356eac3094b83f5bcb9f20b95458de9f61fa70688d8e641ba731672c09d8e2acf51c2c9e9c7bc76e03925c7512be2b92fc4229f3f5cbd006f1f06098ef22d
|
7
|
+
data.tar.gz: 58c46cf815894cccec60a1df5598e2b28e18dc431b606de73de5396179c7d5c83e7043ffb72c39cd66da9b56c49c1ee3fba2d3d2a7cd8f945822e53133cf7152
|
@@ -9,16 +9,16 @@ class PasswordProtectedFile
|
|
9
9
|
private_class_method :new
|
10
10
|
|
11
11
|
def self.open(file_name, password)
|
12
|
+
assert_valid_filename(file_name)
|
12
13
|
assert_file_exists(file_name)
|
13
14
|
assert_valid_password(password)
|
14
|
-
assert_valid_filename(file_name)
|
15
15
|
new(file_name, password).tap { |o| o.__send__(:open_existing) }
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.create(file_name, password, data = '')
|
19
|
+
assert_valid_filename(file_name)
|
19
20
|
assert_file_does_not_exist(file_name)
|
20
21
|
assert_valid_password(password)
|
21
|
-
assert_valid_filename(file_name)
|
22
22
|
new(file_name, password).tap { |o| o.__send__(:create_new, data) }
|
23
23
|
end
|
24
24
|
|
@@ -27,8 +27,7 @@ class PasswordProtectedFile
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def data=(new_data)
|
30
|
-
|
31
|
-
fail InvalidStringEncodingError unless new_data.encoding == Encoding::UTF_8
|
30
|
+
assert_valid_data(new_data)
|
32
31
|
@data = new_data.clone
|
33
32
|
write_file
|
34
33
|
end
|
@@ -104,26 +103,27 @@ class PasswordProtectedFile
|
|
104
103
|
SecureRandom.random_bytes(SALT_BYTES)
|
105
104
|
end
|
106
105
|
|
106
|
+
def self.assert_valid_filename(file_name)
|
107
|
+
unless file_name.is_a?(String) && !file_name.empty? && Dir.exist?(File.dirname(file_name))
|
108
|
+
fail InvalidFilenameError.new("Invalid filename given: #{file_name.inspect}")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
107
112
|
def self.assert_file_exists(file_name)
|
108
|
-
|
109
|
-
fail FileNotFoundError.new("File #{file_name} not found")
|
113
|
+
fail FileNotFoundError.new("File #{file_name} not found") unless File.exist?(file_name)
|
110
114
|
end
|
111
115
|
|
112
116
|
def self.assert_file_does_not_exist(file_name)
|
113
|
-
|
114
|
-
fail FilenameNotAvailableError.new("File #{file_name} already exists")
|
117
|
+
fail FilenameNotAvailableError.new("File #{file_name} already exists") if File.exist?(file_name)
|
115
118
|
end
|
116
119
|
|
117
120
|
def self.assert_valid_password(password)
|
118
|
-
|
119
|
-
fail InvalidPasswordError.new("Invalid password given: #{password.inspect}")
|
121
|
+
fail InvalidPasswordError.new("Invalid password given: #{password.inspect}") unless password.is_a?(String) && password.length > 0
|
120
122
|
end
|
121
123
|
|
122
|
-
def
|
123
|
-
|
124
|
-
|
125
|
-
Dir.exist?(File.dirname(file_name))
|
126
|
-
fail InvalidFilenameError.new("Invalid filename given: #{file_name.inspect}")
|
124
|
+
def assert_valid_data(d)
|
125
|
+
fail InvalidDataError.new("Expected String, got #{d.class}") unless d.instance_of?(String)
|
126
|
+
fail InvalidStringEncodingError.new("Expected utf-8, got #{d.encoding}") unless d.encoding == Encoding::UTF_8
|
127
127
|
end
|
128
128
|
|
129
129
|
class PasswordProtectedFileError < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: password_protected_file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Post
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An easy way to create files protected by a password
|
14
14
|
email: post.isaac@gmail.com
|