opensecret 0.0.913 → 0.0.941
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/.yardopts +3 -0
- data/README.md +129 -19
- data/Rakefile +0 -9
- data/bin/opensecret +1 -1
- data/lib/{opensecret/plugins.io/cipher/crypto.rb → crypto/amalgam.rb} +6 -8
- data/lib/crypto/collect.rb +139 -0
- data/lib/crypto/engineer.rb +201 -0
- data/lib/crypto/verify.rb +33 -0
- data/lib/extension/array.rb +133 -0
- data/lib/{opensecret/additions → extension}/dir.rb +0 -0
- data/lib/extension/file.rb +56 -0
- data/lib/extension/hash.rb +33 -0
- data/lib/extension/string.rb +349 -0
- data/lib/factbase/facts.opensecret.io.ini +28 -0
- data/lib/logging/gem.logging.rb +133 -0
- data/lib/opensecret.rb +102 -45
- data/lib/opensecret/executors/crypt.keys/crypt.keys.ini +0 -53
- data/lib/session/{session.rb → attributes.rb} +60 -5
- data/lib/session/exceptions.rb +53 -0
- data/lib/session/fact.finder.rb +684 -0
- data/lib/session/user.home.rb +49 -0
- data/lib/usecase/usecase.rb +245 -0
- data/lib/usecase/usecases/init.rb +190 -0
- data/lib/usecase/usecases/on.rb +33 -0
- data/lib/usecase/usecases/safe.rb +95 -0
- data/lib/version.rb +1 -1
- metadata +22 -17
- data/lib/opensecret/additions/array.rb +0 -117
- data/lib/opensecret/additions/string.rb +0 -312
- data/lib/opensecret/commons/eco.cmdline.rb +0 -446
- data/lib/opensecret/eco.do.rb +0 -46
- data/lib/opensecret/plugins.io/error/eco.exceptions.rb +0 -24
- data/lib/opensecret/plugins.io/facts/fact.chars.rb +0 -66
- data/lib/opensecret/plugins.io/facts/fact.factor.rb +0 -156
- data/lib/opensecret/plugins.io/facts/fact.locator.rb +0 -105
- data/lib/opensecret/plugins.io/facts/fact.reader.rb +0 -137
- data/lib/opensecret/plugins.io/facts/fact.tree.rb +0 -661
- data/lib/opensecret/plugins.io/logs/log.object.rb +0 -89
- data/lib/opensecret/plugins.io/logs/logging.rb +0 -203
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
module OpenSecret
|
4
|
+
|
5
|
+
# This class verifies domain names, email addresses and othe external
|
6
|
+
# reference data.
|
7
|
+
class Verify
|
8
|
+
|
9
|
+
# Register two fundamental opensecret crypt pointers
|
10
|
+
#
|
11
|
+
# - an opensecret domain like » **lecturers@harvard**
|
12
|
+
# - the url to a backend store like Git, S3 or an SSH accessible drive.
|
13
|
+
#
|
14
|
+
# The domain will be extended to cover verified internet domains.
|
15
|
+
# They will also latch onto LDAP domains so when admins add, revoke
|
16
|
+
# or remove users, their opensecret access is adjusted accordingly.
|
17
|
+
#
|
18
|
+
# @param domain [String] the DOMAIN eg lecturers@harvard for your family or work group.
|
19
|
+
# @param store_url [String] the STORE_URL for connecting to the backend storage service
|
20
|
+
#
|
21
|
+
def self.vreify_domain domain, store_url
|
22
|
+
|
23
|
+
# -> read config file map
|
24
|
+
# -> create new domain in map
|
25
|
+
# -> add type and store url to map
|
26
|
+
# -> backup configuration
|
27
|
+
# -> overwrite the ini config file
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# Reopen the core ruby Array class and add the below methods to it.
|
5
|
+
#
|
6
|
+
# Case Sensitivity rules for [ALL] the below methods that are
|
7
|
+
# added to the core Ruby string class.
|
8
|
+
#
|
9
|
+
# For case insensitive behaviour make sure you downcase both the
|
10
|
+
# string object and the parameter strings (or strings within
|
11
|
+
# other parameter objects, like arrays and hashes).
|
12
|
+
class Array
|
13
|
+
|
14
|
+
|
15
|
+
# Log the array using our logging mixin by printing every array
|
16
|
+
# item into its own log line. In most cases we (the array) are
|
17
|
+
# a list of strings, however if not, each item's to_string method
|
18
|
+
# is invoked and the result printed using one log line.
|
19
|
+
#
|
20
|
+
# The INFO log level is used to log the lines - if this is not
|
21
|
+
# appropriate create a (level) parameterized log lines method.
|
22
|
+
def log_lines
|
23
|
+
|
24
|
+
self.each do |line|
|
25
|
+
clean_line = line.to_s.chomp.gsub("\\n","")
|
26
|
+
log.info(x) { line } if clean_line.length > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Get the text [in between] this and that delimeter [exclusively].
|
33
|
+
# Exclusively means the returned text [does not] include either of
|
34
|
+
# the matched delimeters (although an unmatched instance of [this]
|
35
|
+
# delimeter may appear in the in-between text).
|
36
|
+
#
|
37
|
+
# --------------------
|
38
|
+
# Multiple Delimiters
|
39
|
+
# --------------------
|
40
|
+
#
|
41
|
+
# When multiple delimiters exist, the text returned is in between the
|
42
|
+
#
|
43
|
+
# [a] - first occurrence of [this] delimeter AND the
|
44
|
+
# [b] - 1st occurrence of [that] delimeter [AFTER] the 1st delimiter
|
45
|
+
#
|
46
|
+
# Instances of [that] delimiter occurring before [this] are ignored.
|
47
|
+
# The text could contain [this] delimeter instances but is guaranteed
|
48
|
+
# not to contain a [that] delimeter.
|
49
|
+
#
|
50
|
+
# -----------
|
51
|
+
# Parameters
|
52
|
+
# -----------
|
53
|
+
#
|
54
|
+
# this_delimiter : begin delimeter (not included in returned string)
|
55
|
+
# that_delimiter : end delimeter (not included in returned string)
|
56
|
+
#
|
57
|
+
# -----------
|
58
|
+
# Exceptions
|
59
|
+
# -----------
|
60
|
+
#
|
61
|
+
# An exception (error) will be thrown if
|
62
|
+
#
|
63
|
+
# => any nil (or empties) exist in the input parameters
|
64
|
+
# => [this] delimeter does not appear in the in_string
|
65
|
+
# => [that] delimeter does not appear after [this] one
|
66
|
+
#
|
67
|
+
def before_and_after begin_delimeter, end_delimeter
|
68
|
+
|
69
|
+
Throw.if_nil_or_empty_strings [ self, begin_delimeter, end_delimeter ]
|
70
|
+
|
71
|
+
before_after_lines = []
|
72
|
+
in_middle_bit = false
|
73
|
+
|
74
|
+
self.each do |candidate_line|
|
75
|
+
|
76
|
+
is_middle_boundary = !in_middle_bit && candidate_line.downcase.include?(begin_delimeter.downcase)
|
77
|
+
if is_middle_boundary
|
78
|
+
in_middle_bit = true
|
79
|
+
next
|
80
|
+
end
|
81
|
+
|
82
|
+
unless in_middle_bit
|
83
|
+
before_after_lines.push candidate_line
|
84
|
+
next
|
85
|
+
end
|
86
|
+
|
87
|
+
#--
|
88
|
+
#-- Now we are definitely in the middle bit.
|
89
|
+
#-- Let's check for the middle end delimeter
|
90
|
+
#--
|
91
|
+
if candidate_line.downcase.include? end_delimeter.downcase
|
92
|
+
in_middle_bit = false
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
return before_after_lines
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def middlle_bit begin_delimeter, end_delimeter
|
103
|
+
|
104
|
+
Throw.if_nil_or_empty_strings [ self, begin_delimeter, end_delimeter ]
|
105
|
+
|
106
|
+
middle_lines = []
|
107
|
+
in_middle_bit = false
|
108
|
+
|
109
|
+
self.each do |candidate_line|
|
110
|
+
|
111
|
+
is_middle_boundary = !in_middle_bit && candidate_line.downcase.include?(begin_delimeter.downcase)
|
112
|
+
if is_middle_boundary
|
113
|
+
in_middle_bit = true
|
114
|
+
next
|
115
|
+
end
|
116
|
+
|
117
|
+
end_of_middle = in_middle_bit && candidate_line.downcase.include?(end_delimeter.downcase)
|
118
|
+
return middle_lines if end_of_middle
|
119
|
+
|
120
|
+
#--
|
121
|
+
#-- We are definitely in the middle bit.
|
122
|
+
#--
|
123
|
+
middle_lines.push(candidate_line) if in_middle_bit
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
unreachable_str = "This point should be unreachable unless facts are ended."
|
128
|
+
raise RuntimeError.new unreachable_str
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
end
|
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Reopen the core ruby File class and add the below methods to it.
|
4
|
+
class File
|
5
|
+
|
6
|
+
# This method adds (logging its own contents) behaviour to
|
7
|
+
# the standard library {File} class. If this File points to
|
8
|
+
# a directory - that folder's single level content files are
|
9
|
+
# listed inside the logs.
|
10
|
+
#
|
11
|
+
# The <tt>DEBUG</tt> log level is used for logging. To change this
|
12
|
+
# create a new parameterized method.
|
13
|
+
#
|
14
|
+
# @param file_context [String] context denotes the whys and wherefores of this file.
|
15
|
+
def log_contents file_context
|
16
|
+
|
17
|
+
## This will fail - add physical raise statement.
|
18
|
+
Throw.if_not_exists self
|
19
|
+
|
20
|
+
log.debug(x) { "# -- ------------------------------------------------------------------------ #" }
|
21
|
+
log.debug(x) { "# -- ------------------------------------------------------------------------ #" }
|
22
|
+
log.debug(x) { "# -- The File Path to Log => #{self}" }
|
23
|
+
|
24
|
+
hr_file_size = PrettyPrint.byte_size( File.size(self) )
|
25
|
+
dotless_extension = File.extname( self )[1..-1]
|
26
|
+
parent_dir_name = File.basename( File.dirname( self ) )
|
27
|
+
file_name = File.basename self
|
28
|
+
is_zip = dotless_extension.eql? "zip"
|
29
|
+
|
30
|
+
log.debug(x) { "# -- ------------------------------------------------------------------------ #" }
|
31
|
+
log.debug(x) { "# -- File Name => #{file_name}" }
|
32
|
+
log.debug(x) { "# -- File Size => #{hr_file_size}" }
|
33
|
+
log.debug(x) { "# -- File Type => #{file_context}" }
|
34
|
+
log.debug(x) { "# -- In Folder => #{parent_dir_name}" }
|
35
|
+
log.debug(x) { "# -- ------------------------------------------------------------------------ #" }
|
36
|
+
|
37
|
+
log.debug(x) { "File #{file_name} is a zip (binary) file." } if is_zip
|
38
|
+
return if is_zip
|
39
|
+
|
40
|
+
File.open( self, "r") do | file_obj |
|
41
|
+
line_no = 1
|
42
|
+
file_obj.each_line do | file_line |
|
43
|
+
line_num = sprintf '%03d', line_no
|
44
|
+
clean_line = file_line.chomp.strip
|
45
|
+
log.debug(x) { "# -- [#{line_num}] - #{clean_line}" }
|
46
|
+
line_no += 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
log.debug(x) { "# -- ------------------------------------------------------------------------ #" }
|
51
|
+
log.debug(x) { "# -- [#{file_context}] End of File [ #{File.basename(self)} ]" }
|
52
|
+
log.debug(x) { "# -- ------------------------------------------------------------------------ #" }
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Reopen the core ruby Hash class and add the below methods to it.
|
4
|
+
class Hash
|
5
|
+
|
6
|
+
# This method adds (logging its own contents) behaviour to
|
7
|
+
# the standard library {Hash} class.
|
8
|
+
#
|
9
|
+
# @note This behaviour does not consider that SECRETS may be inside
|
10
|
+
# the key value maps - it logs itself without a care in the world.
|
11
|
+
# This functionality must be included if this behaviourr is used by
|
12
|
+
# any cryptography classes.
|
13
|
+
#
|
14
|
+
# The <tt>DEBUG</tt> log level is used for logging. To change this
|
15
|
+
# create a new parameterized method.
|
16
|
+
def log_contents
|
17
|
+
|
18
|
+
log.debug(x) { "# --- ----------------------------------------------" }
|
19
|
+
log.debug(x) { "# --- Map has [#{self.length}] key/value pairs." }
|
20
|
+
log.debug(x) { "# --- ----------------------------------------------" }
|
21
|
+
|
22
|
+
self.each do |the_key, the_value|
|
23
|
+
|
24
|
+
padded_key = sprintf '%-33s', the_key
|
25
|
+
log.debug(x) { "# --- #{padded_key} => #{the_value}" }
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
log.debug(x) { "# --- ----------------------------------------------" }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,349 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
|
4
|
+
# Reopen the core ruby String class and add the below methods to it.
|
5
|
+
#
|
6
|
+
# Case Sensitivity rules for [ALL] the below methods that are
|
7
|
+
# added to the core Ruby string class.
|
8
|
+
#
|
9
|
+
# For case insensitive behaviour make sure you downcase both the
|
10
|
+
# string object and the parameter strings (or strings within
|
11
|
+
# other parameter objects, like arrays and hashes).
|
12
|
+
class String
|
13
|
+
|
14
|
+
|
15
|
+
# Get the text [in between] this and that delimeter [exclusively].
|
16
|
+
# Exclusively means the returned text [does not] include either of
|
17
|
+
# the matched delimeters (although an unmatched instance of [this]
|
18
|
+
# delimeter may appear in the in-between text).
|
19
|
+
#
|
20
|
+
# ### Multiple Delimiters
|
21
|
+
#
|
22
|
+
# When multiple delimiters exist, the text returned is in between the
|
23
|
+
#
|
24
|
+
# - first occurrence of [this] delimeter AND the
|
25
|
+
# - 1st occurrence of [that] delimeter [AFTER] the 1st delimiter
|
26
|
+
#
|
27
|
+
# Instances of [that] delimiter occurring before [this] are ignored.
|
28
|
+
# The text could contain [this] delimeter instances but is guaranteed
|
29
|
+
# not to contain a [that] delimeter.
|
30
|
+
#
|
31
|
+
# @throw an exception (error) will be thrown if
|
32
|
+
#
|
33
|
+
# - any nil (or empties) exist in the input parameters
|
34
|
+
# - **this** delimeter does not appear in the in_string
|
35
|
+
# - **that** delimeter does not appear after [this] one
|
36
|
+
#
|
37
|
+
# @param this_delimeter [String] begin delimeter (not included in returned string)
|
38
|
+
# @param that_delimeter [String] end delimeter (not included in returned string)
|
39
|
+
#
|
40
|
+
# @return [String] the text in between (excluding) the two parameter delimiters
|
41
|
+
def in_between this_delimeter, that_delimeter
|
42
|
+
|
43
|
+
raise ArgumentError, "This string is NIL or empty." if self.nil? || self.empty?
|
44
|
+
raise ArgumentError, "Begin delimiter is NIL or empty." if this_delimiter.nil? || this_delimiter.empty?
|
45
|
+
raise ArgumentError, "End delimiter is NIL or empty." if that_delimiter.nil? || that_delimiter.empty?
|
46
|
+
|
47
|
+
scanner_1 = StringScanner.new self
|
48
|
+
scanner_1.scan_until /#{this_delimeter}/
|
49
|
+
scanner_2 = StringScanner.new scanner_1.post_match
|
50
|
+
scanner_2.scan_until /#{that_delimeter}/
|
51
|
+
|
52
|
+
in_between_text = scanner_2.pre_match.strip
|
53
|
+
log.info(ere){ in_between_text }
|
54
|
+
|
55
|
+
return in_between_text
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# Flatten (lower) a camel cased string and add periods to
|
61
|
+
# denote separation where the capital letters used to be.
|
62
|
+
#
|
63
|
+
# Example behaviour is illustrated
|
64
|
+
#
|
65
|
+
# - in => ObjectOriented
|
66
|
+
# - out => object.oriented
|
67
|
+
#
|
68
|
+
# Even when a capital letter does not lead lowercase characters
|
69
|
+
# the behaviour should resemble this.
|
70
|
+
#
|
71
|
+
# - in => SuperX
|
72
|
+
# - out => super.x
|
73
|
+
#
|
74
|
+
#
|
75
|
+
# And if every letter is uppercase, each one represents its
|
76
|
+
# own section like this.
|
77
|
+
#
|
78
|
+
# - in => BEAST
|
79
|
+
# - out => b.e.a.s.t
|
80
|
+
#
|
81
|
+
# @return [String] a flatten (period separated) version of this camel cased string
|
82
|
+
def do_flatten
|
83
|
+
|
84
|
+
snapped_str = ""
|
85
|
+
self.each_char do |this_char|
|
86
|
+
is_lower = "#{this_char}".is_all_lowercase?
|
87
|
+
snapped_str += "." unless is_lower || snapped_str.empty?
|
88
|
+
snapped_str += this_char.downcase
|
89
|
+
end
|
90
|
+
|
91
|
+
return snapped_str
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
# Return true if every character in this string is lowercase.
|
98
|
+
# Note that if this string is empty this method returns true.
|
99
|
+
#
|
100
|
+
# @return true if every alpha character in this string is lowercase
|
101
|
+
def is_all_lowercase?
|
102
|
+
return self.downcase.eql? self
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
# Flatten (lower) a camel cased string and add periods to
|
108
|
+
# denote separation where the capital letters used to be.
|
109
|
+
# The inverse operation to [ do_flatten ] which resurrects
|
110
|
+
# this (expected) period separated string changing it back
|
111
|
+
# to a camel (mountain) cased string.
|
112
|
+
#
|
113
|
+
# Example behaviour is illustrated
|
114
|
+
#
|
115
|
+
# - in => object.oriented
|
116
|
+
# - out => ObjectOriented
|
117
|
+
#
|
118
|
+
# Even when a single character exists to the right of the period
|
119
|
+
# the behaviour should resemble this.
|
120
|
+
#
|
121
|
+
# - in => super.x
|
122
|
+
# - out => SuperX
|
123
|
+
#
|
124
|
+
#
|
125
|
+
# And if every letter is period separated
|
126
|
+
#
|
127
|
+
# - in => b.e.a.s.t
|
128
|
+
# - out => BEAST
|
129
|
+
#
|
130
|
+
# @return [String] camel cased version of this flattened (period separated) string
|
131
|
+
def un_flatten
|
132
|
+
|
133
|
+
segment_array = self.strip.split "."
|
134
|
+
resurrected_arr = Array.new
|
135
|
+
|
136
|
+
segment_array.each do |seg_word|
|
137
|
+
resurrected_arr.push seg_word.capitalize
|
138
|
+
end
|
139
|
+
|
140
|
+
undone_str = resurrected_arr.join
|
141
|
+
log.info(x){ "unflattening => [#{self}] and resurrecting to => [#{undone_str}]" }
|
142
|
+
|
143
|
+
return undone_str
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
# --
|
150
|
+
# Return true if the [little string] within this
|
151
|
+
# string object is both
|
152
|
+
# --
|
153
|
+
# a] topped by the parameter prefix AND
|
154
|
+
# b] tailed by the parameter postfix
|
155
|
+
# --
|
156
|
+
# -----------------------------------------
|
157
|
+
# In the below example [true] is returned
|
158
|
+
# -----------------------------------------
|
159
|
+
# --
|
160
|
+
# This [String] => "Hey [<-secrets->] are juicy."
|
161
|
+
# little string => "secrets"
|
162
|
+
# topped string => "[<-"
|
163
|
+
# tailed string => "->]"
|
164
|
+
# --
|
165
|
+
# Why true? Because the little string "secret" is
|
166
|
+
# (wrapped) topped by "[<-" and tailed by "->]"
|
167
|
+
# --
|
168
|
+
# -----------------------------------------
|
169
|
+
# Assumptions | Constraints | Boundaries
|
170
|
+
# -----------------------------------------
|
171
|
+
# --
|
172
|
+
# - all matches are [case sensitive]
|
173
|
+
# - this string must contain little_str
|
174
|
+
# - one strike and its true
|
175
|
+
# (if little string appears more than once)
|
176
|
+
# so => "all secrets, most [<-secrets->] r juicy"
|
177
|
+
# => true as long as (at least) one is wrapped
|
178
|
+
# --
|
179
|
+
# --
|
180
|
+
def has_wrapped? little_str, prefix, postfix
|
181
|
+
|
182
|
+
return self.include?( prefix + little_str + postfix )
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
# Sandwich the first occurrence of a substring in
|
188
|
+
# this string with the specified pre and postfix.
|
189
|
+
#
|
190
|
+
# This string contains the little string and an
|
191
|
+
# IN-PLACE change is performed with the first
|
192
|
+
# occurrence of the little string being prefixed
|
193
|
+
# and postfixed with the 2 parameter strings.
|
194
|
+
#
|
195
|
+
# Example of sandwiching [wrapping]
|
196
|
+
#
|
197
|
+
# - [String] => "Hey secrets are juicy."
|
198
|
+
# - [To_Wrap] => "secrets"
|
199
|
+
# - [Prefix] => "[<-"
|
200
|
+
# - [Postfix] => "->]"
|
201
|
+
#
|
202
|
+
# [String] => "Hey [<-secrets->] are juicy."
|
203
|
+
#
|
204
|
+
# This string IS changed in place.
|
205
|
+
def sandwich_substr to_wrap_str, prefix, postfix
|
206
|
+
|
207
|
+
occurs_index = self.downcase.index to_wrap_str.downcase
|
208
|
+
self.insert occurs_index, prefix
|
209
|
+
shifted_index = occurs_index + prefix.length + to_wrap_str.length
|
210
|
+
self.insert shifted_index, postfix
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
# The parameter is a list of character sequences and TRUE is returned
|
216
|
+
# if EVERY ONE of the character sequences is always found nestled somewhere
|
217
|
+
# within this string. The matching is case-sensitive.
|
218
|
+
#
|
219
|
+
# The parameter array can be [empty] but not nil. And the harboured
|
220
|
+
# character sequences can neither be nil nor empty.
|
221
|
+
#
|
222
|
+
# @param word_array [Array] array of string words for the inclusivity test
|
223
|
+
#
|
224
|
+
# @return [Boolean] true if EVERY ONE of the char sequences appear somewhere in this string
|
225
|
+
def includes_all? word_array
|
226
|
+
|
227
|
+
raise ArgumentError, "This string is NIL" if self.nil?
|
228
|
+
raise ArgumentError, "The parameter word array is NIL" if word_array.nil?
|
229
|
+
|
230
|
+
word_array.each do |word|
|
231
|
+
|
232
|
+
raise ArgumentError, "The word array #{word_array} contains a nil value." if word.nil?
|
233
|
+
return false unless self.include? word
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
return true
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
# The parameter is a list of character sequences and TRUE is returned
|
243
|
+
# if any one of the character sequences can be found nestled somewhere
|
244
|
+
# within this string. The matching is case-sensitive.
|
245
|
+
#
|
246
|
+
# The parameter array can be [empty] but not nil. And the harboured
|
247
|
+
# character sequences can neither be nil nor empty.
|
248
|
+
#
|
249
|
+
# @param word_array [Array] array of string words for the inclusivity test
|
250
|
+
#
|
251
|
+
# @return [Boolean] true if string includes ANY one of the character sequences in array
|
252
|
+
def includes_any? word_array
|
253
|
+
|
254
|
+
raise ArgumentError, "This string is NIL" if self.nil?
|
255
|
+
raise ArgumentError, "The parameter word array is NIL" if word_array.nil?
|
256
|
+
|
257
|
+
word_array.each do |word|
|
258
|
+
|
259
|
+
raise ArgumentError, "The word array #{word_array} contains a nil value." if word.nil?
|
260
|
+
return true if self.include? word
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
return false
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
# --
|
270
|
+
# Encrypt this string with the parameter encryption/decryption key
|
271
|
+
# and return the encrypted text as a new string.
|
272
|
+
# --
|
273
|
+
# decrypt_key => the key that will decrypt the output string
|
274
|
+
# --
|
275
|
+
# --
|
276
|
+
def encrypt decrypt_key
|
277
|
+
|
278
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
279
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
280
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
281
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
282
|
+
|
283
|
+
###### ON Linux improve by changing to OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
|
284
|
+
###### ON Linux improve by changing to Digest::SHA2.hexdigest decrypt_key
|
285
|
+
###### ON Linux improve by changing to OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
|
286
|
+
###### ON Linux improve by changing to Digest::SHA2.hexdigest decrypt_key
|
287
|
+
###### ON Linux improve by changing to OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
|
288
|
+
###### ON Linux improve by changing to Digest::SHA2.hexdigest decrypt_key
|
289
|
+
###### ON Linux improve by changing to OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
|
290
|
+
###### ON Linux improve by changing to Digest::SHA2.hexdigest decrypt_key
|
291
|
+
|
292
|
+
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC').encrypt
|
293
|
+
cipher.key = Digest::SHA1.hexdigest decrypt_key
|
294
|
+
crypted = cipher.update(self) + cipher.final
|
295
|
+
encrypted_text = crypted.unpack('H*')[0].upcase
|
296
|
+
|
297
|
+
return encrypted_text
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
# --
|
303
|
+
# Decrypt this string with the parameter encryption/decryption key
|
304
|
+
# and return the decrypted text as a new string.
|
305
|
+
# --
|
306
|
+
# encrypt_key => the key the input string was encrypted with
|
307
|
+
# --
|
308
|
+
# --
|
309
|
+
def decrypt encrypt_key
|
310
|
+
|
311
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
312
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
313
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
314
|
+
## ----> Write a RE-CRYPT method that goes through a folder - decrypting and recrypting
|
315
|
+
|
316
|
+
###### ON Linux improve by changing to OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
|
317
|
+
###### ON Linux improve by changing to Digest::SHA2.hexdigest decrypt_key
|
318
|
+
###### ON Linux improve by changing to OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
|
319
|
+
###### ON Linux improve by changing to Digest::SHA2.hexdigest decrypt_key
|
320
|
+
###### ON Linux improve by changing to OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
|
321
|
+
###### ON Linux improve by changing to Digest::SHA2.hexdigest decrypt_key
|
322
|
+
|
323
|
+
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC').decrypt
|
324
|
+
cipher.key = Digest::SHA1.hexdigest encrypt_key
|
325
|
+
uncrypted = [self].pack("H*").unpack("C*").pack("c*")
|
326
|
+
decrypted_text = cipher.update(uncrypted) + cipher.final
|
327
|
+
|
328
|
+
return decrypted_text
|
329
|
+
|
330
|
+
end
|
331
|
+
|
332
|
+
|
333
|
+
# Log the string which is expected to be delineated.
|
334
|
+
# If the string originated from a file it will be logged
|
335
|
+
# line by line. If no line delineation the string will be
|
336
|
+
# dumped just as a blob.
|
337
|
+
#
|
338
|
+
# The INFO log level is used to log the lines - if this is not
|
339
|
+
# appropriate create a (level) parameterized log lines method.
|
340
|
+
def log_lines
|
341
|
+
|
342
|
+
self.each_line do |line|
|
343
|
+
clean_line = line.chomp.gsub("\\n","")
|
344
|
+
log.info(x) { line } if clean_line.length > 0
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
348
|
+
|
349
|
+
end
|