lg_pod_plugin 1.1.7.4 → 1.1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lg_pod_plugin/db/database.rb +1 -1
- data/lib/lg_pod_plugin/downloader/downloader.rb +9 -48
- data/lib/lg_pod_plugin/downloader/l_cache.rb +58 -66
- data/lib/lg_pod_plugin/downloader/overload_cache.rb +14 -284
- data/lib/lg_pod_plugin/downloader/request.rb +2 -4
- data/lib/lg_pod_plugin/git/github_api.rb +2 -49
- data/lib/lg_pod_plugin/git/github_archive.rb +11 -32
- data/lib/lg_pod_plugin/git/gitlab_api.rb +42 -42
- data/lib/lg_pod_plugin/git/gitlab_archive.rb +7 -80
- data/lib/lg_pod_plugin/git/http_download.rb +3 -8
- data/lib/lg_pod_plugin/installer/PodDownload +0 -0
- data/lib/lg_pod_plugin/installer/install.rb +15 -12
- data/lib/lg_pod_plugin/installer/main.rb +5 -0
- data/lib/lg_pod_plugin/net/l_uri.rb +1 -34
- data/lib/lg_pod_plugin/pod/external_pod.rb +0 -1
- data/lib/lg_pod_plugin/pod/release-pod.rb +4 -4
- data/lib/lg_pod_plugin/utils/file_path.rb +5 -0
- data/lib/lg_pod_plugin/utils/l_util.rb +0 -24
- data/lib/lg_pod_plugin/version.rb +1 -1
- data/lib/lg_pod_plugin.rb +1 -1
- metadata +9 -26
- data/lib/lg_pod_plugin/config/lockfile_model.rb +0 -58
- data/lib/lg_pod_plugin/config/podspec.rb +0 -266
- data/lib/lg_pod_plugin/utils/aes-crypt.rb +0 -82
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lg_pod_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dongzb01
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocoapods
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.14.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.14.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: claide
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,20 +44,6 @@ dependencies:
|
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '2.0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: activesupport
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - '='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 7.0.8
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - '='
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 7.0.8
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: bacon
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,20 +92,20 @@ dependencies:
|
|
106
92
|
requirements:
|
107
93
|
- - "~>"
|
108
94
|
- !ruby/object:Gem::Version
|
109
|
-
version: '1.
|
95
|
+
version: '1.7'
|
110
96
|
- - ">="
|
111
97
|
- !ruby/object:Gem::Version
|
112
|
-
version: 1.
|
98
|
+
version: 1.7.2
|
113
99
|
type: :runtime
|
114
100
|
prerelease: false
|
115
101
|
version_requirements: !ruby/object:Gem::Requirement
|
116
102
|
requirements:
|
117
103
|
- - "~>"
|
118
104
|
- !ruby/object:Gem::Version
|
119
|
-
version: '1.
|
105
|
+
version: '1.7'
|
120
106
|
- - ">="
|
121
107
|
- !ruby/object:Gem::Version
|
122
|
-
version: 1.
|
108
|
+
version: 1.7.2
|
123
109
|
description: 拦截pod_install 方法, 并设置 pod 方法参数列表
|
124
110
|
email:
|
125
111
|
- 1060545231@qq.com
|
@@ -139,8 +125,6 @@ files:
|
|
139
125
|
- lib/command/update.rb
|
140
126
|
- lib/lg_pod_plugin.rb
|
141
127
|
- lib/lg_pod_plugin/config/l_config.rb
|
142
|
-
- lib/lg_pod_plugin/config/lockfile_model.rb
|
143
|
-
- lib/lg_pod_plugin/config/podspec.rb
|
144
128
|
- lib/lg_pod_plugin/config/target.rb
|
145
129
|
- lib/lg_pod_plugin/db/database.rb
|
146
130
|
- lib/lg_pod_plugin/downloader/downloader.rb
|
@@ -163,7 +147,6 @@ files:
|
|
163
147
|
- lib/lg_pod_plugin/net/net-ping.rb
|
164
148
|
- lib/lg_pod_plugin/pod/external_pod.rb
|
165
149
|
- lib/lg_pod_plugin/pod/release-pod.rb
|
166
|
-
- lib/lg_pod_plugin/utils/aes-crypt.rb
|
167
150
|
- lib/lg_pod_plugin/utils/file_path.rb
|
168
151
|
- lib/lg_pod_plugin/utils/l_util.rb
|
169
152
|
- lib/lg_pod_plugin/utils/log.rb
|
@@ -188,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
171
|
- !ruby/object:Gem::Version
|
189
172
|
version: '0'
|
190
173
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
174
|
+
rubygems_version: 3.5.6
|
192
175
|
signing_key:
|
193
176
|
specification_version: 4
|
194
177
|
summary: 封装了自定义podfile 中pod 方法
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'cocoapods-core'
|
2
|
-
|
3
|
-
module LgPodPlugin
|
4
|
-
|
5
|
-
class LockfileModel
|
6
|
-
attr_accessor :lockfile
|
7
|
-
attr_accessor :release_pods
|
8
|
-
attr_accessor :external_sources_data
|
9
|
-
attr_accessor :checkout_options_data
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.from_file
|
15
|
-
lockfile = LProject.shared.lockfile
|
16
|
-
unless lockfile
|
17
|
-
lockfile_model = LockfileModel.new
|
18
|
-
lockfile_model.lockfile = nil
|
19
|
-
lockfile_model.release_pods = {}
|
20
|
-
lockfile_model.checkout_options_data = {}
|
21
|
-
lockfile_model.external_sources_data = {}
|
22
|
-
return lockfile_model
|
23
|
-
end
|
24
|
-
release_pods = Hash.new
|
25
|
-
pods = lockfile.send(:generate_pod_names_and_versions)
|
26
|
-
pods.each do |element|
|
27
|
-
if LUtils.is_a_string?(element) || element.is_a?(Hash)
|
28
|
-
key = element.is_a?(Hash) ? element.keys.first : element
|
29
|
-
next unless key
|
30
|
-
if key.include?(" ")
|
31
|
-
pod_name = LUtils.pod_real_name(key.split(" ").first)
|
32
|
-
else
|
33
|
-
pod_name = key
|
34
|
-
end
|
35
|
-
tag = key[/(?<=\().*?(?=\))/]
|
36
|
-
release_pods[pod_name] = tag
|
37
|
-
else
|
38
|
-
next
|
39
|
-
end
|
40
|
-
end
|
41
|
-
lockfile_model = LockfileModel.new
|
42
|
-
lockfile_model.lockfile = lockfile
|
43
|
-
lockfile_model.release_pods = release_pods
|
44
|
-
lockfile_model.checkout_options_data = lockfile.send(:checkout_options_data)
|
45
|
-
lockfile_model.checkout_options_data = {} unless lockfile_model.checkout_options_data
|
46
|
-
lockfile_model.external_sources_data = lockfile.send(:external_sources_data)
|
47
|
-
lockfile_model.external_sources_data = {} unless lockfile_model.external_sources_data
|
48
|
-
lockfile_model
|
49
|
-
end
|
50
|
-
|
51
|
-
def checkout_options_for_pod_named(name)
|
52
|
-
return {} unless @lockfile
|
53
|
-
hash = @lockfile.checkout_options_for_pod_named(name)
|
54
|
-
hash ? hash : {}
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
@@ -1,266 +0,0 @@
|
|
1
|
-
require 'cocoapods'
|
2
|
-
require 'cocoapods-core'
|
3
|
-
|
4
|
-
module LgPodPlugin
|
5
|
-
|
6
|
-
class PodSpec
|
7
|
-
attr_reader :spec
|
8
|
-
attr_accessor :json_files
|
9
|
-
attr_accessor :source_files
|
10
|
-
|
11
|
-
public
|
12
|
-
def self.form_file(path)
|
13
|
-
begin
|
14
|
-
spec = Pod::Specification.from_file(path)
|
15
|
-
return PodSpec.new(spec)
|
16
|
-
rescue
|
17
|
-
return nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
public
|
22
|
-
def prepare_command
|
23
|
-
json = self.to_pretty_json
|
24
|
-
return nil unless json
|
25
|
-
hash = JSON.parse json
|
26
|
-
hash["prepare_command"]
|
27
|
-
end
|
28
|
-
|
29
|
-
public
|
30
|
-
def to_pretty_json(*a)
|
31
|
-
require 'json'
|
32
|
-
JSON.pretty_generate(self.spec.to_hash, *a) << "\n"
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
public
|
37
|
-
def self.form_string(string, path)
|
38
|
-
begin
|
39
|
-
#Work around for Rubinius incomplete encoding in 1.9 mode
|
40
|
-
if string.respond_to?(:encoding) && string.encoding.name != 'UTF-8'
|
41
|
-
string = string.force_encoding("gb2312").force_encoding("utf-8")
|
42
|
-
end
|
43
|
-
spec = Pod::Specification.from_string string, path
|
44
|
-
return PodSpec.new(spec)
|
45
|
-
rescue
|
46
|
-
return nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.form_pod_spec(spec)
|
51
|
-
return PodSpec.new(spec)
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.form_json(object)
|
55
|
-
begin
|
56
|
-
spec = Pod::Specification.from_json(object)
|
57
|
-
return PodSpec.new(spec)
|
58
|
-
rescue
|
59
|
-
return nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def initialize(spec)
|
64
|
-
if spec == nil
|
65
|
-
@spec = nil
|
66
|
-
@json_files = Hash.new
|
67
|
-
@source_files = Hash.new
|
68
|
-
return
|
69
|
-
end
|
70
|
-
set = Set[]
|
71
|
-
@spec = spec
|
72
|
-
attributes_hash = spec.send(:attributes_hash)
|
73
|
-
return unless attributes_hash.is_a?(Hash)
|
74
|
-
license = attributes_hash["license"]
|
75
|
-
if license.is_a?(Hash)
|
76
|
-
license_file = license["file"]
|
77
|
-
set.add(license_file) if license_file
|
78
|
-
else
|
79
|
-
set.add("LICENSE")
|
80
|
-
end
|
81
|
-
# 解析主模块依赖信息
|
82
|
-
set.merge(parse_subspec_with(attributes_hash))
|
83
|
-
subspecs = spec.subspecs
|
84
|
-
unless subspecs.is_a?(Array)
|
85
|
-
self.source_files = parse_with_set set
|
86
|
-
if self.source_files.has_key?("*")
|
87
|
-
self.source_files.delete("*")
|
88
|
-
self.source_files["All"] = "All"
|
89
|
-
end
|
90
|
-
self.json_files = spec.to_pretty_json
|
91
|
-
return
|
92
|
-
end
|
93
|
-
subspecs.each do |sub_spec|
|
94
|
-
sub_attributes_hash = sub_spec.send(:attributes_hash)
|
95
|
-
next unless sub_attributes_hash && sub_attributes_hash.is_a?(Hash)
|
96
|
-
sub_set = self.parse_subspec_with(sub_attributes_hash)
|
97
|
-
next if sub_set.empty?
|
98
|
-
set.merge(sub_set)
|
99
|
-
end
|
100
|
-
self.source_files = parse_with_set set
|
101
|
-
if self.source_files.has_key?("*")
|
102
|
-
self.source_files.delete("*")
|
103
|
-
self.source_files["All"] = "All"
|
104
|
-
end
|
105
|
-
self.json_files = spec.to_pretty_json
|
106
|
-
end
|
107
|
-
|
108
|
-
public
|
109
|
-
def write_to_file(path)
|
110
|
-
LCache.write_spec(@spec, path)
|
111
|
-
end
|
112
|
-
|
113
|
-
def parse_with_set(set)
|
114
|
-
new_hash = Hash.new
|
115
|
-
set.each do |element|
|
116
|
-
if element.start_with?("**/")
|
117
|
-
new_hash["All"] = "All"
|
118
|
-
elsif element.include?("/")
|
119
|
-
str = element.split("/", 0).first
|
120
|
-
new_hash[str] = str unless str.empty?
|
121
|
-
elsif element.start_with?("**.") || element.start_with?("*.")
|
122
|
-
new_hash["All"] = "All"
|
123
|
-
elsif element.start_with?("*.framework") || element.include?("*.a")
|
124
|
-
new_hash["All"] = "All"
|
125
|
-
else
|
126
|
-
new_hash[element] = element unless element.empty?
|
127
|
-
end
|
128
|
-
end
|
129
|
-
new_hash
|
130
|
-
end
|
131
|
-
|
132
|
-
# 公共解析解析subspec
|
133
|
-
def parse_subspec_with(hash)
|
134
|
-
set = Set[]
|
135
|
-
source_files = self.parse_source_files(hash["source_files"])
|
136
|
-
set.merge(source_files) unless source_files.empty?
|
137
|
-
resources = self.parse_resource_files(hash["resource"] ||= hash["resources"])
|
138
|
-
set.merge(resources) unless resources.empty?
|
139
|
-
resource_bundles = self.parse_resource_bundles(hash["resource_bundle"] ||= hash["resource_bundles"])
|
140
|
-
set.merge(resource_bundles) unless resource_bundles.empty?
|
141
|
-
project_header_files = self.parse_project_header_files(hash["project_header_files"])
|
142
|
-
set.merge(resource_bundles) unless project_header_files.empty?
|
143
|
-
private_header_files = self.parse_private_header_files(hash["private_header_files"])
|
144
|
-
set.merge(private_header_files) unless private_header_files.empty?
|
145
|
-
vendored_frameworks = self.parse_vendored_frameworks(hash["vendored_frameworks"])
|
146
|
-
set.merge(vendored_frameworks) unless vendored_frameworks.empty?
|
147
|
-
vendored_library = self.parse_vendored_library(hash["vendored_library"] ||= hash["vendored_libraries"])
|
148
|
-
set.merge(vendored_library) unless vendored_library.empty?
|
149
|
-
#parse_preserve_path
|
150
|
-
preserve_paths = self.parse_preserve_path(hash["preserve_path"] ||= hash["preserve_paths"])
|
151
|
-
set.merge(preserve_paths) unless preserve_paths.empty?
|
152
|
-
module_map = self.parse_module_map(hash["module_map"])
|
153
|
-
set.merge(module_map) unless module_map.empty?
|
154
|
-
ios_hash = hash["ios"]
|
155
|
-
if ios_hash && ios_hash.is_a?(Hash)
|
156
|
-
|
157
|
-
ios_source_files = self.parse_source_files(ios_hash["source_files"])
|
158
|
-
set.merge(ios_source_files) unless ios_source_files.empty?
|
159
|
-
|
160
|
-
ios_resources = self.parse_resource_files(ios_hash["resource"] ||= ios_hash["resources"])
|
161
|
-
set.merge(ios_resources) unless ios_resources.empty?
|
162
|
-
|
163
|
-
ios_resource_bundles = self.parse_resource_bundles(ios_hash["resource_bundle"] ||= ios_hash["resource_bundles"])
|
164
|
-
set.merge(ios_resource_bundles) unless ios_resource_bundles.empty?
|
165
|
-
|
166
|
-
ios_project_header_files = self.parse_project_header_files(ios_hash["project_header_files"])
|
167
|
-
set.merge(ios_project_header_files) unless ios_project_header_files.empty?
|
168
|
-
|
169
|
-
ios_private_header_files = self.parse_private_header_files(ios_hash["private_header_files"])
|
170
|
-
set.merge(ios_private_header_files) unless ios_private_header_files.empty?
|
171
|
-
|
172
|
-
ios_vendored_frameworks = self.parse_vendored_frameworks(ios_hash["vendored_frameworks"])
|
173
|
-
set.merge(ios_vendored_frameworks) unless ios_vendored_frameworks.empty?
|
174
|
-
|
175
|
-
ios_vendored_library = self.parse_vendored_library(ios_hash["vendored_library"] ||= ios_hash["vendored_libraries"])
|
176
|
-
set.merge(ios_vendored_library) unless ios_vendored_library.empty?
|
177
|
-
|
178
|
-
ios_preserve_paths = self.parse_preserve_path(ios_hash["preserve_path"] ||= ios_hash["preserve_paths"])
|
179
|
-
set.merge(ios_preserve_paths) unless ios_preserve_paths.empty?
|
180
|
-
|
181
|
-
ios_module_map = self.parse_module_map(ios_hash["module_map"])
|
182
|
-
set.merge(ios_module_map) unless ios_module_map.empty?
|
183
|
-
|
184
|
-
end
|
185
|
-
set
|
186
|
-
end
|
187
|
-
|
188
|
-
# 公共解析文件路径的方法
|
189
|
-
def parse_public_source_files(source_files)
|
190
|
-
return Array.new unless source_files
|
191
|
-
array = Array.new
|
192
|
-
if LUtils.is_a_string?(source_files)
|
193
|
-
array.append(source_files) unless source_files.empty?
|
194
|
-
elsif source_files.is_a?(Array)
|
195
|
-
source_files.each do |element|
|
196
|
-
next unless LUtils.is_a_string?(element)
|
197
|
-
array.append(element) unless element.empty?
|
198
|
-
end
|
199
|
-
elsif source_files.is_a?(Hash)
|
200
|
-
source_files.each do |_, val|
|
201
|
-
if LUtils.is_a_string?(val)
|
202
|
-
array.append(val) unless val.empty?
|
203
|
-
elsif val.is_a?(Array)
|
204
|
-
val.each do |element|
|
205
|
-
next unless LUtils.is_a_string?(element)
|
206
|
-
array.append(element) unless element.empty?
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
array
|
212
|
-
end
|
213
|
-
|
214
|
-
# 解析source_files路径
|
215
|
-
def parse_source_files(source_files)
|
216
|
-
self.parse_public_source_files(source_files)
|
217
|
-
end
|
218
|
-
|
219
|
-
# 解析 resource所在路径
|
220
|
-
def parse_resource_files(source_files)
|
221
|
-
self.parse_public_source_files(source_files)
|
222
|
-
end
|
223
|
-
|
224
|
-
# 解析public_header_files字段的值
|
225
|
-
def parse_public_header_files(source_files)
|
226
|
-
self.parse_public_source_files(source_files)
|
227
|
-
end
|
228
|
-
|
229
|
-
# 解析 parse_resource_bundles
|
230
|
-
def parse_resource_bundles(source_files)
|
231
|
-
self.parse_public_source_files(source_files)
|
232
|
-
end
|
233
|
-
|
234
|
-
# 解析 project_header_files
|
235
|
-
def parse_project_header_files(source_files)
|
236
|
-
self.parse_public_source_files(source_files)
|
237
|
-
end
|
238
|
-
|
239
|
-
# 解析 private_header_files
|
240
|
-
def parse_private_header_files(source_files)
|
241
|
-
self.parse_public_source_files(source_files)
|
242
|
-
end
|
243
|
-
|
244
|
-
# 解析 vendored_frameworks
|
245
|
-
def parse_vendored_frameworks(source_files)
|
246
|
-
self.parse_public_source_files(source_files)
|
247
|
-
end
|
248
|
-
|
249
|
-
# 解析 parse_vendored_library
|
250
|
-
def parse_vendored_library(source_files)
|
251
|
-
self.parse_public_source_files(source_files)
|
252
|
-
end
|
253
|
-
|
254
|
-
# 解析 parse_preserve_path
|
255
|
-
def parse_preserve_path(source_files)
|
256
|
-
self.parse_public_source_files(source_files)
|
257
|
-
end
|
258
|
-
|
259
|
-
# 解析 module_map
|
260
|
-
def parse_module_map(source_files)
|
261
|
-
self.parse_public_source_files(source_files)
|
262
|
-
end
|
263
|
-
|
264
|
-
end
|
265
|
-
|
266
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
# The encrypt_data and decrypt_data methods are Copyright (c) 2007 Brent Sowers
|
4
|
-
# and have been included with prior permission.
|
5
|
-
#
|
6
|
-
# Copyright (c) 2012 Gurpartap Singh
|
7
|
-
#
|
8
|
-
# MIT License
|
9
|
-
#
|
10
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
11
|
-
# a copy of this software and associated documentation files (the
|
12
|
-
# "Software"), to deal in the Software without restriction, including
|
13
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
14
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
16
|
-
# the following conditions:
|
17
|
-
#
|
18
|
-
# The above copyright notice and this permission notice shall be
|
19
|
-
# included in all copies or substantial portions of the Software.
|
20
|
-
#
|
21
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
22
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
24
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
25
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
26
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
27
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28
|
-
|
29
|
-
require 'openssl'
|
30
|
-
|
31
|
-
module AESCrypt
|
32
|
-
def self.encrypt(message, password)
|
33
|
-
Base64.encode64(self.encrypt_data(message.to_s.strip, password, nil, "AES-256-ECB"))
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.decrypt(message, password)
|
37
|
-
base64_decoded = Base64.decode64(message.to_s.strip)
|
38
|
-
self.decrypt_data(base64_decoded, password, nil, "AES-256-ECB")
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.key_digest(password)
|
42
|
-
OpenSSL::Digest::SHA256.new(password).digest
|
43
|
-
end
|
44
|
-
|
45
|
-
# Decrypts a block of data (encrypted_data) given an encryption key
|
46
|
-
# and an initialization vector (iv). Keys, iv's, and the data
|
47
|
-
# returned are all binary strings. Cipher_type should be
|
48
|
-
# "AES-256-CBC", "AES-256-ECB", or any of the cipher types
|
49
|
-
# supported by OpenSSL. Pass nil for the iv if the encryption type
|
50
|
-
# doesn't use iv's (like ECB).
|
51
|
-
#:return: => String
|
52
|
-
#:arg: encrypted_data => String
|
53
|
-
#:arg: key => String
|
54
|
-
#:arg: iv => String
|
55
|
-
#:arg: cipher_type => String
|
56
|
-
def self.decrypt_data(encrypted_data, key, iv, cipher_type)
|
57
|
-
aes = OpenSSL::Cipher::Cipher.new(cipher_type)
|
58
|
-
aes.decrypt
|
59
|
-
aes.key = key
|
60
|
-
aes.iv = iv if iv != nil
|
61
|
-
aes.update(encrypted_data) + aes.final
|
62
|
-
end
|
63
|
-
|
64
|
-
# Encrypts a block of data given an encryption key and an
|
65
|
-
# initialization vector (iv). Keys, iv's, and the data returned
|
66
|
-
# are all binary strings. Cipher_type should be "AES-256-CBC",
|
67
|
-
# "AES-256-ECB", or any of the cipher types supported by OpenSSL.
|
68
|
-
# Pass nil for the iv if the encryption type doesn't use iv's (like
|
69
|
-
# ECB).
|
70
|
-
#:return: => String
|
71
|
-
#:arg: data => String
|
72
|
-
#:arg: key => String
|
73
|
-
#:arg: iv => String
|
74
|
-
#:arg: cipher_type => String
|
75
|
-
def self.encrypt_data(data, key, iv, cipher_type)
|
76
|
-
aes = OpenSSL::Cipher::Cipher.new(cipher_type)
|
77
|
-
aes.encrypt
|
78
|
-
aes.key = key
|
79
|
-
aes.iv = iv if iv != nil
|
80
|
-
aes.update(data) + aes.final
|
81
|
-
end
|
82
|
-
end
|