unidom-common 1.0.1 → 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.
- checksums.yaml +4 -4
- data/README.md +228 -27
- data/app/models/unidom/common/concerns/aes256_cryptor.rb +49 -0
- data/app/models/unidom/common/concerns/sha512_digester.rb +29 -0
- data/lib/unidom/common.rb +2 -0
- data/lib/unidom/common/numeration.rb +11 -0
- data/lib/unidom/common/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95243ebeb2e8156ec28f4ca6c76d1bda4b2dfb9a
|
4
|
+
data.tar.gz: c6dd4045999cb395eb98659c01895480df1bba1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcde6b74d223e1371ffe43e04a555edbcdb6c9acec410a1112a7d360feedda7635450ef3d7573b7478e069c1fdf1d4762be55a13037a8935eb5e9f62d5259ac4
|
7
|
+
data.tar.gz: d05202257ad1d5ae256a866c58d6da0785050b32dfe104f1654337ea5d3ada6c0a4fc748154bc6c4b73ca1ab16eb8ca56866ecb5e8b036dc6a0d316c5a14569b
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ The migration enabled the PostgreSQL uuid-ossp extension.
|
|
28
28
|
include Unidom::Common::Concerns::ModelExtension
|
29
29
|
```
|
30
30
|
|
31
|
-
##
|
31
|
+
## Model Extension concern
|
32
32
|
```ruby
|
33
33
|
class Project < ActiveRecord::Base
|
34
34
|
|
@@ -81,28 +81,104 @@ project.enabled? # true
|
|
81
81
|
Project.notation_boolean_column_where(:enabled, true) # All enabled projects
|
82
82
|
```
|
83
83
|
|
84
|
+
## Numeration
|
85
|
+
```ruby
|
86
|
+
binary = 'some string'
|
87
|
+
hex = Unidom::Common::Numeration.hex binary # "736f6d6520737472696e67"
|
88
|
+
# convert a binary (usually a string) to it's hex string
|
89
|
+
|
90
|
+
text = Unidom::Common::Numeration.rev_hex hex # "some string"
|
91
|
+
# convert a hex string to its text value
|
92
|
+
```
|
93
|
+
|
94
|
+
## AES 256 Cryptor
|
95
|
+
```ruby
|
96
|
+
class IdentityCard
|
97
|
+
|
98
|
+
include Unidom::Common::Concerns::Aes256Cryptor
|
99
|
+
attr_accessor :identification_number, :encrypted_identification_number
|
100
|
+
|
101
|
+
def initialize(identification_number)
|
102
|
+
self.identification_number = identification_number
|
103
|
+
@aes_256_key = OpenSSL::Cipher::AES.new(256, 'CBC').random_key
|
104
|
+
end
|
105
|
+
|
106
|
+
def encrypt_identification_number
|
107
|
+
encrypt identification_number, key: @aes_256_key
|
108
|
+
end
|
109
|
+
|
110
|
+
def decrypt_identification_number
|
111
|
+
decrypt encrypted_identification_number, key: @aes_256_key
|
112
|
+
end
|
113
|
+
|
114
|
+
def cryption_padding
|
115
|
+
8
|
116
|
+
end
|
117
|
+
# If the #cryption_padding method is missed, the default padding 9 is used instead
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
identification_number = '9527'
|
122
|
+
identity_card = IdentityCard.new '9527'
|
123
|
+
encrypted = identity_card.encrypt_identification_number
|
124
|
+
decrypted = identity_card.decrypt_identification_number
|
125
|
+
# The decrypted should equal to identification_number
|
126
|
+
# The AES 256 Cryptor also has the #hex_encrypt and the #hex_decrypt methods
|
127
|
+
```
|
128
|
+
|
129
|
+
## SHA 512 Digester
|
130
|
+
```ruby
|
131
|
+
class IdentityCard
|
132
|
+
|
133
|
+
include Unidom::Common::Concerns::Sha512Digester
|
134
|
+
attr_accessor :identification_number
|
135
|
+
|
136
|
+
def initialize(identification_number)
|
137
|
+
self.identification_number = identification_number
|
138
|
+
end
|
139
|
+
|
140
|
+
def digest_identification_number
|
141
|
+
digest identification_number, pepper: self.class.name
|
142
|
+
end
|
143
|
+
|
144
|
+
def hex_digest_identification_number
|
145
|
+
hex_digest identification_number, pepper: self.class.name
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
identity_card = IdentityCard.new '9527'
|
151
|
+
digested = identity_card.digest_identification_number
|
152
|
+
hex_digested = identity_card.hex_digest_identification_number
|
153
|
+
hex_digested == Unidom::Common::Numeration.hex digested # true
|
154
|
+
```
|
155
|
+
|
84
156
|
## ActiveRecord Migration Naming Convention
|
85
157
|
### Domain Models (200YMMDDHHMMSS)
|
86
158
|
|
87
159
|
<table class='table table-striped table-hover'>
|
88
160
|
<caption></caption>
|
89
161
|
<thead>
|
162
|
+
|
90
163
|
<tr>
|
91
164
|
<th>Ruby Gem</th>
|
92
165
|
<th>Migration</th>
|
93
166
|
<th>Model</th>
|
94
167
|
<th>Description</th>
|
95
168
|
</tr>
|
169
|
+
|
96
170
|
</thead>
|
97
171
|
<tbody>
|
172
|
+
|
98
173
|
<tr>
|
99
|
-
<td>unidom-common
|
174
|
+
<td>[](https://github.com/topbitdu/unidom-common)</td>
|
100
175
|
<td>200001DDHHMMSS</td>
|
101
176
|
<td>-</td>
|
102
177
|
<td>The Common domain model engine includes the common models. 常用领域模型引擎包括一些常用的模型。</td>
|
103
178
|
</tr>
|
179
|
+
|
104
180
|
<tr>
|
105
|
-
<td>unidom-visitor
|
181
|
+
<td>[](https://github.com/topbitdu/unidom-visitor)</td>
|
106
182
|
<td>200002DDHHMMSS</td>
|
107
183
|
<td>
|
108
184
|
- Identificating
|
@@ -114,33 +190,158 @@ Project.notation_boolean_column_where(:enabled, true) # All enabled projects
|
|
114
190
|
</td>
|
115
191
|
<td>The Visitor domain model engine includes Identificating, Authenticating, Recognization, Visitor (User & Guest), and Password models. 访问者领域模型引擎包括身份标识、身份鉴别、身份识别、访问者(用户和游客)、密码的模型。</td>
|
116
192
|
</tr>
|
193
|
+
|
194
|
+
<tr>
|
195
|
+
<td>[](https://github.com/topbitdu/unidom-category)</td>
|
196
|
+
<td>200003DDHHMMSS</td>
|
197
|
+
<td>
|
198
|
+
- Category
|
199
|
+
- Categorizing
|
200
|
+
- Category Rollup
|
201
|
+
- Category Associating
|
202
|
+
</td>
|
203
|
+
<td>The Category domain model engine includes Category and its relative models. 类别领域模型引擎包括类别及其相关的模型。</td>
|
204
|
+
</tr>
|
205
|
+
|
206
|
+
<tr>
|
207
|
+
<td>[](https://github.com/topbitdu/unidom-authorization)</td>
|
208
|
+
<td>200004DDHHMMSS</td>
|
209
|
+
<td>
|
210
|
+
- Permission
|
211
|
+
- Authorizing
|
212
|
+
</td>
|
213
|
+
<td>The Authorization domain model engine includes the Permission and Authorizing models. 授权领域模型引擎包括权限、授权的模型。</td>
|
214
|
+
</tr>
|
215
|
+
|
216
|
+
<tr>
|
217
|
+
<td>[](https://github.com/topbitdu/unidom-standard)</td>
|
218
|
+
<td>200006DDHHMMSS</td>
|
219
|
+
<td>
|
220
|
+
- Standard
|
221
|
+
- Standard Associating
|
222
|
+
</td>
|
223
|
+
<td>The Standard domain model engine includes the Standard model and the Standard Associating model. 标准领域模型引擎包括行为标准和标准关联的模型。</td>
|
224
|
+
</tr>
|
225
|
+
|
226
|
+
<tr>
|
227
|
+
<td>[](https://github.com/topbitdu/unidom-party)</td>
|
228
|
+
<td>200101DDHHMMSS</td>
|
229
|
+
<td>
|
230
|
+
- Person
|
231
|
+
- Shop
|
232
|
+
- Company
|
233
|
+
- Government Agency
|
234
|
+
- Party Relation
|
235
|
+
</td>
|
236
|
+
<td>The Party domain model engine includes the Person, Shop, Company, Government Agency, and the Party Relation models. 参与者领域模型引擎包括个人、店铺、公司、政府机构、参与者关系的模型。</td>
|
237
|
+
</tr>
|
238
|
+
|
239
|
+
<tr>
|
240
|
+
<td>[](https://github.com/topbitdu/unidom-certificate)</td>
|
241
|
+
<td>200102DDHHMMSS</td>
|
242
|
+
<td>
|
243
|
+
- Certificating
|
244
|
+
</td>
|
245
|
+
<td>The Certificate domain model engine includes the Certificating model.
|
246
|
+
证书领域模型引擎包括证书认证的模型。</td>
|
247
|
+
</tr>
|
248
|
+
|
249
|
+
<tr>
|
250
|
+
<td>[](https://github.com/topbitdu/unidom-contact)</td>
|
251
|
+
<td>200103DDHHMMSS</td>
|
252
|
+
<td>
|
253
|
+
- Contact Subscription
|
254
|
+
- Email Address
|
255
|
+
</td>
|
256
|
+
<td>The Contact domain model engine includes the Contact Subscription and Email Address models. 联系方式领域模型引擎包括联系方式订阅和电子邮箱地址的模型。</td>
|
257
|
+
</tr>
|
258
|
+
|
259
|
+
<tr>
|
260
|
+
<td>[](https://github.com/topbitdu/unidom-geo)</td>
|
261
|
+
<td>200104DDHHMMSS</td>
|
262
|
+
<td>
|
263
|
+
- Location
|
264
|
+
- Locating
|
265
|
+
</td>
|
266
|
+
<td>The Geo domain model engine includes the Location and Locating models. 地理领域模型引擎包括位置和定位的模型。</td>
|
267
|
+
</tr>
|
268
|
+
|
269
|
+
<tr>
|
270
|
+
<td>[](https://github.com/topbitdu/unidom-article_number)</td>
|
271
|
+
<td>200201DDHHMMSS</td>
|
272
|
+
<td>
|
273
|
+
- Marking
|
274
|
+
- EAN 13 Barcode
|
275
|
+
- EAN 8 Barcode
|
276
|
+
</td>
|
277
|
+
<td>The Article Number domain model engine includes Marking, EAN-13, and EAN-8 models. 物品编码领域模型引擎包括打码、EAN-13和EAN-8的模型。</td>
|
278
|
+
</tr>
|
279
|
+
|
280
|
+
<tr>
|
281
|
+
<td>[](https://github.com/topbitdu/unidom-product)</td>
|
282
|
+
<td>200202DDHHMMSS</td>
|
283
|
+
<td>
|
284
|
+
- Product
|
285
|
+
- Product Associating
|
286
|
+
</td>
|
287
|
+
<td>The Product domain model engine includes Product and Produt Associating models. 产品领域模型引擎包括产品和产品关联的模型。</td>
|
288
|
+
</tr>
|
289
|
+
|
290
|
+
<tr>
|
291
|
+
<td>[](https://github.com/topbitdu/unidom-price)</td>
|
292
|
+
<td>200203DDHHMMSS</td>
|
293
|
+
<td>
|
294
|
+
- Price
|
295
|
+
</td>
|
296
|
+
<td>The Price domain model engine includes Price and its relative models. 价格领域模型引擎包括定价及其相关的模型。</td>
|
297
|
+
</tr>
|
298
|
+
|
299
|
+
<tr>
|
300
|
+
<td>[](https://github.com/topbitdu/unidom-shopping)</td>
|
301
|
+
<td>200205DDHHMMSS</td>
|
302
|
+
<td>
|
303
|
+
- Shopping Cart
|
304
|
+
- Shopping Item
|
305
|
+
</td>
|
306
|
+
<td>The Shopping domain model engine includes Shopping Cart and Shopping Item models. 购物领域模型引擎包括购物车和购物项的模型。</td>
|
307
|
+
</tr>
|
308
|
+
|
309
|
+
<tr>
|
310
|
+
<td>[](https://github.com/topbitdu/unidom-order)</td>
|
311
|
+
<td>200206DDHHMMSS</td>
|
312
|
+
<td>
|
313
|
+
- Order
|
314
|
+
- Order Item
|
315
|
+
- Order Adjustment
|
316
|
+
</td>
|
317
|
+
<td>The Order domain model engine includes Order, Order Item, and Order Adjustment models. 订单领域模型引擎包括订单、订单项和订单调整的模型。</td>
|
318
|
+
</tr>
|
319
|
+
|
320
|
+
<tr>
|
321
|
+
<td>[](https://github.com/topbitdu/unidom-position)</td>
|
322
|
+
<td>200402DDHHMMSS</td>
|
323
|
+
<td>
|
324
|
+
- Occupation
|
325
|
+
- Position
|
326
|
+
- Post
|
327
|
+
- Position Reporting Structure
|
328
|
+
</td>
|
329
|
+
<td>The Position domain model engine includes the Occupation, Position, Post, and Position Reporting Structure models.
|
330
|
+
职位领域模型引擎包括职业、职位、岗位及岗位报告关系模型。</td>
|
331
|
+
</tr>
|
332
|
+
|
333
|
+
<tr>
|
334
|
+
<td>[](https://github.com/topbitdu/unidom-accession)</td>
|
335
|
+
<td>200405DDHHMMSS</td>
|
336
|
+
<td>
|
337
|
+
- Post Fulfillment
|
338
|
+
</td>
|
339
|
+
<td>The Position domain model engine includes the Post Fulfillment and its relative models. 就职领域模型引擎包括岗位履行及其相关的模型。</td>
|
340
|
+
</tr>
|
341
|
+
|
117
342
|
</tbody>
|
118
343
|
</table>
|
119
344
|
|
120
|
-
* unidom-common: 200001DDHHMMSS
|
121
|
-
* unidom-visitor: 200002DDHHMMSS
|
122
|
-
* unidom-category: 200003DDHHMMSS
|
123
|
-
* unidom-authorization: 200004DDHHMMSS
|
124
|
-
* unidom-accounting: 200005DDHHMMSS
|
125
|
-
* unidom-standard: 200006DDHHMMSS
|
126
|
-
|
127
|
-
* unidom-party: 200101DDHHMMSS
|
128
|
-
* unidom-certificate: 200102DDHHMMSS
|
129
|
-
* unidom-contact: 200103DDHHMMSS
|
130
|
-
* unidom-geo: 200104DDHHMMSS
|
131
|
-
* unidom-property: 200105DDHHMMSS
|
132
|
-
|
133
|
-
* unidom-article_number: 200201DDHHMMSS
|
134
|
-
* unidom-product: 200202DDHHMMSS
|
135
|
-
* unidom-price: 200203DDHHMMSS
|
136
|
-
* unidom-commodity: 200204DDHHMMSS
|
137
|
-
* unidom-shopping: 200205DDHHMMSS
|
138
|
-
* unidom-order: 200206DDHHMMSS
|
139
|
-
* unidom-promotion: 200207DDHHMMSS
|
140
|
-
* unidom-payment: 200208DDHHMMSS
|
141
|
-
|
142
|
-
* unidom-position: 200402DDHHMMSS
|
143
|
-
|
144
345
|
### Country Extensions (200YMM9NNNMMSS)
|
145
346
|
The YMM part should be identical to the relative part of the Domain Models.
|
146
347
|
The NNN is the numeric code of [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1 "codes for the names of countries, dependent territories, and special areas of geographical interest").
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Unidom::Common::Concerns::Aes256Cryptor
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do |includer|
|
6
|
+
|
7
|
+
def encrypt(message, key: nil)
|
8
|
+
|
9
|
+
raise ArgumentError.new('The message argument is required.') if message.blank?
|
10
|
+
raise ArgumentError.new('The key argument is required.') if key.blank?
|
11
|
+
|
12
|
+
cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
|
13
|
+
cipher.encrypt
|
14
|
+
cipher.padding = aes_256_padding
|
15
|
+
cipher.key = key
|
16
|
+
|
17
|
+
cipher.update(message)+cipher.final
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def decrypt(encoded, key: nil)
|
22
|
+
|
23
|
+
raise ArgumentError.new('The encoded argument is required.') if encoded.blank?
|
24
|
+
raise ArgumentError.new('The key argument is required.') if key.blank?
|
25
|
+
|
26
|
+
cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
|
27
|
+
cipher.decrypt
|
28
|
+
cipher.padding = aes_256_padding
|
29
|
+
cipher.key = key
|
30
|
+
|
31
|
+
cipher.update(encoded)+cipher.final
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def aes_256_padding
|
36
|
+
respond_to?(:cryption_padding) ? cryption_padding : 9
|
37
|
+
end
|
38
|
+
|
39
|
+
def hex_encrypt(message, key: nil)
|
40
|
+
Unidom::Common::Numeration.hex encrypt(message, key: key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def hex_decrypt(encoded, key: nil)
|
44
|
+
Unidom::Common::Numeration.hex decrypt(Unidom::Common::Numeration.rev_hex(encoded), key: key)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Unidom::Common::Concerns::Sha512Digester
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do |includer|
|
6
|
+
|
7
|
+
def digest(message, pepper: nil)
|
8
|
+
self.class.digest message, pepper: pepper
|
9
|
+
end
|
10
|
+
|
11
|
+
def hex_digest(message, pepper: nil)
|
12
|
+
self.class.hex_digest message, pepper: pepper
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
|
19
|
+
def digest(message, pepper: nil)
|
20
|
+
message.present? ? Digest::SHA512.digest("#{message}_#{Rails.application.secrets[:secret_key_base]}_#{pepper}") : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def hex_digest(message, pepper: nil)
|
24
|
+
message.present? ? Unidom::Common::Numeration.hex(digest(message, pepper: pepper)) : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/unidom/common.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -81,7 +81,9 @@ files:
|
|
81
81
|
- app/assets/stylesheets/unidom/common/application.css
|
82
82
|
- app/controllers/unidom/common/application_controller.rb
|
83
83
|
- app/helpers/unidom/common/application_helper.rb
|
84
|
+
- app/models/unidom/common/concerns/aes256_cryptor.rb
|
84
85
|
- app/models/unidom/common/concerns/model_extension.rb
|
86
|
+
- app/models/unidom/common/concerns/sha512_digester.rb
|
85
87
|
- app/views/layouts/unidom/common/application.html.erb
|
86
88
|
- config/routes.rb
|
87
89
|
- db/migrate/20000101000000_enable_uuid_extension.rb
|
@@ -89,6 +91,7 @@ files:
|
|
89
91
|
- lib/unidom/common.rb
|
90
92
|
- lib/unidom/common/data_helper.rb
|
91
93
|
- lib/unidom/common/engine.rb
|
94
|
+
- lib/unidom/common/numeration.rb
|
92
95
|
- lib/unidom/common/version.rb
|
93
96
|
homepage: http://github.com/topbitdu/unidom-common
|
94
97
|
licenses:
|