carrierwave_easy_encryption 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ data.tar.gz: 5b5c72078f341480cdaba7bb68cc1baa4172871a
4
+ metadata.gz: a3bba8c4a9274ad4a2ada07dfb2f97b0f17a1e4a
5
+ SHA512:
6
+ data.tar.gz: c2cb3bb7791125da1e909b0da92b702c0a8ad74ebe854483b3e243f4e09b62fa6a4473170c4cef1d017fd74d59023053549eafabe88a518a84e2e6e1f9ffdfdc
7
+ metadata.gz: c879ce2c19834ea0e081e3bb36e80d328d10bd1c2b651a9e878369631e4d4c3b22b255fa9ac8d59ccf04c6414701ff8332199c05ef7205c27f2e205b9eefa0ff
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrerwave_easy_encryption.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hywel Carver
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # CarrierWave::EasyEncryption
2
+
3
+ The easiest way to encrypt files uploaded to Rails when you're storing with CarrierWave.
4
+
5
+ Based on `carrierwave_securefile`, but simpler.
6
+
7
+ Tested with Ruby 2 and Rails 4.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'carrerwave_easy_encryption'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install carrerwave_easy_encryption
22
+
23
+ ## Usage
24
+
25
+ ###Add an initializer###
26
+
27
+ CarrierWave::EasyEncryption.configure do |config|
28
+ config.password = "<some long hex digits, e.g. the output of SecureRandom.hex(32)>"
29
+ end`
30
+
31
+ ###Modify the uploaders you want to encrypt###
32
+
33
+ class MyUploader < CarrierWave::Uploader::Base
34
+ process :encrypt
35
+
36
+ def encrypt
37
+ CarrierWave::EasyEncryption::Uploader.secure_file(model, self.file.path.to_s)
38
+ end
39
+ end
40
+
41
+ ###Add controller actions for decrypting files before downloading###
42
+
43
+ def download
44
+ @model = Model.find(params(:id))
45
+ send_data CarrierWave::EasyEncryption::Downloader.download(@model.my_uploader).string, filename: File.basename(@model.my_uploader.path)
46
+ end
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrierwave_easy_encryption/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carrierwave_easy_encryption"
8
+ spec.version = CarrierWave::EasyEncryption::VERSION
9
+ spec.authors = ["Hywel Carver"]
10
+ spec.email = ["h@londonstartuptech.com"]
11
+ spec.description = %q{The easiest way to encrypt your carrierwave files}
12
+ spec.summary = %q{Encrypt all of your carrierwave files with the minimum of effort and the minimum of configuration}
13
+ spec.homepage = "https://github.com/hcarver/carrierwave_easy_encryption"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "gibberish", "~> 1.4.0"
24
+ end
@@ -0,0 +1,45 @@
1
+ require "carrierwave_easy_encryption/version"
2
+ require 'open-uri'
3
+
4
+ module CarrierWave
5
+ module EasyEncryption
6
+ def self.configure
7
+ yield configuration
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= CarrierWave::EasyEncryption::Configuration.new
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :password
16
+ end
17
+
18
+ module Uploader
19
+ def self.secure_file(model=nil, file)
20
+ if !model.nil? && model.id.nil?
21
+ encrypted_file = Tempfile.new('enc').path
22
+ cipher = Gibberish::AES.new(CarrierWave::EasyEncryption.configuration.password)
23
+ cipher.encrypt_file(file, encrypted_file)
24
+ FileUtils.copy(encrypted_file, file)
25
+ File.unlink(encrypted_file)
26
+ file
27
+ end
28
+ end
29
+ end
30
+
31
+ module Downloader
32
+ class << self
33
+ def download(uploader)
34
+ cipher = Gibberish::AES.new(CarrierWave::EasyEncryption.configuration.password)
35
+
36
+ is_local = (uploader._storage == CarrierWave::Storage::File)
37
+ istream = open(is_local ? uploader.path : uploader.url)
38
+ ostream = StringIO.new
39
+ cipher.decrypt_stream(istream, ostream)
40
+ return ostream
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module CarrierWave
2
+ module EasyEncryption
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave_easy_encryption
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hywel Carver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-02-05 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: "1.3"
22
+ type: :development
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ prerelease: false
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id004
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
36
+ name: gibberish
37
+ prerelease: false
38
+ requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: 1.4.0
43
+ type: :runtime
44
+ version_requirements: *id003
45
+ description: The easiest way to encrypt your carrierwave files
46
+ email:
47
+ - h@londonstartuptech.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - carrierwave_easy_encryption.gemspec
61
+ - lib/carrierwave_easy_encryption.rb
62
+ - lib/carrierwave_easy_encryption/version.rb
63
+ homepage: https://github.com/hcarver/carrierwave_easy_encryption
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - *id004
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - *id004
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.14
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Encrypt all of your carrierwave files with the minimum of effort and the minimum of configuration
86
+ test_files: []
87
+