unidom-common 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +82 -0
- data/app/models/unidom/common/concerns/md5_digester.rb +29 -0
- data/app/models/unidom/common/concerns/model_extension.rb +1 -1
- data/app/models/unidom/common/concerns/sha256_digester.rb +29 -0
- data/app/models/unidom/common/concerns/sha384_digester.rb +29 -0
- data/lib/unidom/common.rb +2 -2
- 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: 88c40a102845260fbe5699f42e6d5c2735ffa0c0
|
4
|
+
data.tar.gz: 47f31fb4af3d8fb94cd73568399293dd6c0ebbe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e326b1f17168a898d71f72e2fd2f642d67c85cb8ddaa132a6abd28ff25c1a1a51b0cb3c016d32c630abc151d254c360cc2185004a572ff22309855cc8ad10af
|
7
|
+
data.tar.gz: 9c65b56a55eb3184101a42ead4afaca5b9c0fd0d67b8975ed469fc1f506d5776578c6f213b7423c5135b72920eaf5d00f8a286c8fbd976d47ad6007c8282d851
|
data/README.md
CHANGED
@@ -126,6 +126,87 @@ decrypted = identity_card.decrypt_identification_number
|
|
126
126
|
# The AES 256 Cryptor also has the #hex_encrypt and the #hex_decrypt methods
|
127
127
|
```
|
128
128
|
|
129
|
+
## MD 5 Digester
|
130
|
+
```ruby
|
131
|
+
class IdentityCard
|
132
|
+
|
133
|
+
include Unidom::Common::Concerns::Md5Digester
|
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
|
+
|
156
|
+
## SHA 256 Digester
|
157
|
+
```ruby
|
158
|
+
class IdentityCard
|
159
|
+
|
160
|
+
include Unidom::Common::Concerns::Sha256Digester
|
161
|
+
attr_accessor :identification_number
|
162
|
+
|
163
|
+
def initialize(identification_number)
|
164
|
+
self.identification_number = identification_number
|
165
|
+
end
|
166
|
+
|
167
|
+
def digest_identification_number
|
168
|
+
digest identification_number, pepper: self.class.name
|
169
|
+
end
|
170
|
+
|
171
|
+
def hex_digest_identification_number
|
172
|
+
hex_digest identification_number, pepper: self.class.name
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
identity_card = IdentityCard.new '9527'
|
178
|
+
digested = identity_card.digest_identification_number
|
179
|
+
hex_digested = identity_card.hex_digest_identification_number
|
180
|
+
hex_digested == Unidom::Common::Numeration.hex digested # true
|
181
|
+
```
|
182
|
+
|
183
|
+
## SHA 384 Digester
|
184
|
+
```ruby
|
185
|
+
class IdentityCard
|
186
|
+
|
187
|
+
include Unidom::Common::Concerns::Sha384Digester
|
188
|
+
attr_accessor :identification_number
|
189
|
+
|
190
|
+
def initialize(identification_number)
|
191
|
+
self.identification_number = identification_number
|
192
|
+
end
|
193
|
+
|
194
|
+
def digest_identification_number
|
195
|
+
digest identification_number, pepper: self.class.name
|
196
|
+
end
|
197
|
+
|
198
|
+
def hex_digest_identification_number
|
199
|
+
hex_digest identification_number, pepper: self.class.name
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
identity_card = IdentityCard.new '9527'
|
205
|
+
digested = identity_card.digest_identification_number
|
206
|
+
hex_digested = identity_card.hex_digest_identification_number
|
207
|
+
hex_digested == Unidom::Common::Numeration.hex digested # true
|
208
|
+
```
|
209
|
+
|
129
210
|
## SHA 512 Digester
|
130
211
|
```ruby
|
131
212
|
class IdentityCard
|
@@ -153,6 +234,7 @@ hex_digested = identity_card.hex_digest_identification_number
|
|
153
234
|
hex_digested == Unidom::Common::Numeration.hex digested # true
|
154
235
|
```
|
155
236
|
|
237
|
+
|
156
238
|
## ActiveRecord Migration Naming Convention
|
157
239
|
### Domain Models (200YMMDDHHMMSS)
|
158
240
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Unidom::Common::Concerns::Md5Digester
|
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::MD5.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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Unidom::Common::Concerns::Sha256Digester
|
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::SHA256.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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Unidom::Common::Concerns::Sha384Digester
|
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::SHA384.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
@@ -5,8 +5,8 @@ require 'unidom/common/numeration'
|
|
5
5
|
module Unidom
|
6
6
|
module Common
|
7
7
|
|
8
|
-
NULL_UUID = '00000000-0000-0000-0000-000000000000'
|
9
|
-
SELF = '~'
|
8
|
+
NULL_UUID = '00000000-0000-0000-0000-000000000000' #.freeze
|
9
|
+
SELF = '~' #.freeze
|
10
10
|
|
11
11
|
#OPENED_AT = Time.utc(1970).freeze
|
12
12
|
#CLOSED_AT = Time.utc(3000).freeze
|
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.2'
|
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-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -82,7 +82,10 @@ files:
|
|
82
82
|
- app/controllers/unidom/common/application_controller.rb
|
83
83
|
- app/helpers/unidom/common/application_helper.rb
|
84
84
|
- app/models/unidom/common/concerns/aes256_cryptor.rb
|
85
|
+
- app/models/unidom/common/concerns/md5_digester.rb
|
85
86
|
- app/models/unidom/common/concerns/model_extension.rb
|
87
|
+
- app/models/unidom/common/concerns/sha256_digester.rb
|
88
|
+
- app/models/unidom/common/concerns/sha384_digester.rb
|
86
89
|
- app/models/unidom/common/concerns/sha512_digester.rb
|
87
90
|
- app/views/layouts/unidom/common/application.html.erb
|
88
91
|
- config/routes.rb
|