easy-crypto 0.0.2 → 0.0.3

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
  SHA256:
3
- metadata.gz: 71d9dc94fea524015ddc5f2494d20b6617bae68d440b5e253dd223738b7b10b8
4
- data.tar.gz: 0d90bae4172a48debda1ba2e9c222ed0f99deb537ba5ae86201bf2ce41134bc1
3
+ metadata.gz: f4ad3e00c48d1045ceb274232305aff4a182022395bbe2b610e2b348cf10e18b
4
+ data.tar.gz: 00adb629016b33ba4a3f905488abdbf9de0f44b4cf53a43b4d76d18d7f9d8e73
5
5
  SHA512:
6
- metadata.gz: 88db5fd08c7d5ecbcc4dc6695d848d2a052afa41be8e0c0d78a0b3a3572ad60d3eb25016346856bddbad2e964b6e57de9e5518ef24293a85c150b612a15b5e61
7
- data.tar.gz: 6a2f42b3f6c2c8dd3148068c213591537fc832bc58842f039a5837567774cb64cc538bf81b757d68e6b2f3ef21bbf68b24ec04b55bb9106a2d86cd6c1acae416
6
+ metadata.gz: 0b7d604a6a3f4b50f3c4f15d687e2c3833e5116e85b4989b1c91ee0f527e8a897596078c7fb84e77c464f68f3cfbd8a44be698a399bb7a234618c361a34aae71
7
+ data.tar.gz: 96da1fe387f964f5a1d7a15ea3ef8ae1e81f2544a9a2a9a3c50922473c8acf23fb163bccad7e4670ecbb41b7e6181cdfcdbd2d587c580dcf991f39903c6987ca
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy-crypto (0.0.2)
4
+ easy-crypto (0.0.3)
5
5
  openssl (~> 2.1.1, >= 2.1.1)
6
6
 
7
7
  GEM
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Istvan Szenasi
3
+ Copyright (c) 2018 Emarsys Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # EasyCrypto
1
+ # EasyCrypto [![Build Status](https://travis-ci.org/emartech/ruby-easy-crypto.svg?branch=master)](https://travis-ci.org/emartech/ruby-easy-crypto) [![Gem Version](https://badge.fury.io/rb/easy-crypto.svg)](https://badge.fury.io/rb/easy-crypto)
2
2
 
3
3
  Provides simple wrappers around the openssl crypto implementation.
4
4
 
@@ -20,7 +20,19 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ ### Encrypt with previously derived key
24
+
25
+ ```ruby
26
+ require 'easycrypto'
27
+
28
+ key_password = 'secret password'
29
+ plain_text = 'data to encrypt ...'
30
+
31
+ ecrypto = EasyCrypto::Crypto.new
32
+
33
+ key = EasyCrypto::Key.generate(key_password)
34
+ ecrypto.encrypt_with_key(key, plain_text)
35
+ ```
24
36
 
25
37
  ## License
26
38
 
@@ -10,6 +10,7 @@ module EasyCrypto
10
10
 
11
11
  def encrypt_with_key(key, plaintext)
12
12
  validate_key_type(key)
13
+ validate_plaintext(plaintext)
13
14
 
14
15
  iv = OpenSSL::Random.random_bytes(Crypto::IV_LEN)
15
16
  cipher = create_cipher(key, iv)
@@ -22,7 +23,12 @@ module EasyCrypto
22
23
  private
23
24
 
24
25
  def validate_key_type(key)
25
- raise TypeError 'key must have Key type' unless key.is_a?(EasyCrypto::Key)
26
+ raise TypeError, 'key must have Key type' unless key.is_a?(EasyCrypto::Key)
27
+ end
28
+
29
+ def validate_plaintext(plaintext)
30
+ raise TypeError, 'Encryptable data must be a string' unless plaintext.is_a?(String)
31
+ raise ArgumentError, 'Encryptable data must not be empty' if plaintext.empty?
26
32
  end
27
33
 
28
34
  def create_cipher(key, iv)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyCrypto
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
@@ -12,5 +12,21 @@ RSpec.describe EasyCrypto::Crypto do
12
12
  encrypted = ecrypto.encrypt_with_key(key, 'plain text')
13
13
  expect(encrypted).not_to include("\n")
14
14
  end
15
+
16
+ it 'raise error if the encryptable data is not a string' do
17
+ ecrypto = EasyCrypto::Crypto.new
18
+ key = EasyCrypto::Key.generate('key password', 12)
19
+ expect{
20
+ ecrypto.encrypt_with_key(key, 1234)
21
+ }.to raise_error(TypeError, 'Encryptable data must be a string')
22
+ end
23
+
24
+ it 'raise error if the encryptable data is empty' do
25
+ ecrypto = EasyCrypto::Crypto.new
26
+ key = EasyCrypto::Key.generate('key password', 12)
27
+ expect{
28
+ ecrypto.encrypt_with_key(key, '')
29
+ }.to raise_error(ArgumentError, 'Encryptable data must not be empty')
30
+ end
15
31
  end
16
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-crypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emarsys Security
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2018-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler