mongoid-kms 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7c1b83c180198a4549ef4e4dc2694b0052e9856
4
- data.tar.gz: 30a2fe3e4a67249d8d2c3c37c7c963db4e58bf14
3
+ metadata.gz: 0ebbda51ef80389eaecf46b37d1a0f51df878c4d
4
+ data.tar.gz: 3f34f7aa3d3a6fbe073f4d012f79fee453cc56c2
5
5
  SHA512:
6
- metadata.gz: 8502628dd512b3f50467fb05345c96d83cf9efd28f24e9a801c93c1a9e180d9ec284f1e45e2ec6e3024a4600399125441412f3969ebae0a1aa750797ae83b74d
7
- data.tar.gz: 850ffc9f2655164b9e56c89e8dd456684c27e786db9674d705df01c3d61de885beb1c212c845e14c822eb3b799bcc3fe573dbd75525a047bd7f491d88fc1c400
6
+ metadata.gz: 39ea9ef53495efc0e3772b8536e1030fd83f1f1fa476140bb04d08d2d4a3414f002c85c4710ce666a12a9ecf88e4faee1498a3fcef8a410625d03ca628feae75
7
+ data.tar.gz: ff30e0484db64775723c05c56dd500128efbdd184c1942879b10311cad04aaa017c81881ce134bf2aa2b8a2b714bd4c7a3e72290925b93f6d04f3b7e3b7e2cb6
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Kms
3
- VERSION = "0.0.28"
3
+ VERSION = "0.0.29"
4
4
  end
5
5
  end
data/lib/mongoid/kms.rb CHANGED
@@ -47,6 +47,14 @@ module Mongoid
47
47
  BSON
48
48
  end
49
49
  end
50
+
51
+ def binary_factory(data)
52
+ if defined? Moped::BSON
53
+ Moped::BSON::Binary.new(:generic, data)
54
+ elsif defined? BSON
55
+ BSON::Binary.new(data)
56
+ end
57
+ end
50
58
  end
51
59
 
52
60
  # Instance methods
@@ -68,7 +76,7 @@ module Mongoid
68
76
  if value.nil?
69
77
  self.send("#{encrypted_field_name}=", nil)
70
78
  else
71
- self.send("#{encrypted_field_name}=", Mongoid::Kms.bson_class::Binary.new(self.class.encrypt_field(self, field_name, value)))
79
+ self.send("#{encrypted_field_name}=", Mongoid::Kms.binary_factory(self.class.encrypt_field(self, field_name, value)))
72
80
  end
73
81
  end
74
82
  end
@@ -87,4 +87,33 @@ describe Mongoid::Kms do
87
87
  o.bla
88
88
  end
89
89
 
90
+ it "works with embedded documents" do
91
+ class ParentClass
92
+ include Mongoid::Document
93
+
94
+ embeds_one :child_class, class_name: "ChildClass"
95
+
96
+ field :unsecure, type: String
97
+ end
98
+
99
+ class ChildClass
100
+ include Mongoid::Document
101
+ include Mongoid::Kms
102
+
103
+ embedded_in :parent_class
104
+
105
+ secure_field :secure, type: String
106
+ field :unsecure, type: String
107
+ end
108
+
109
+ o = ParentClass.create!(unsecure: "wonder woman")
110
+ o.child_class = ChildClass.new(secure: "invisible ship", unsecure: "a whip")
111
+ o.save!
112
+
113
+ o.reload
114
+ expect(o.unsecure).to eq("wonder woman")
115
+ expect(o.child_class.secure).to eq("invisible ship")
116
+ expect(o.child_class.unsecure).to eq("a whip")
117
+ end
118
+
90
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-kms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Winslett