keyczar_ruby 0.0.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.
- data/.gitignore +7 -0
- data/Gemfile +3 -0
- data/README +24 -0
- data/Rakefile +13 -0
- data/ext/keyczar_ruby/extconf.rb +10 -0
- data/ext/keyczar_ruby/keyczar_ruby.cc +96 -0
- data/keyczar_ruby.gemspec +29 -0
- data/lib/keyczar_ruby/version.rb +3 -0
- metadata +117 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
A ruby interface to the keyczar crypto library. Provides basic encrypt,
|
2
|
+
decrypt, sign and verify methods.
|
3
|
+
|
4
|
+
This is just a wrapper around the c++ version of keyczar. You will need
|
5
|
+
keyczar-cpp in order to use it. Find keyczar-cpp here:
|
6
|
+
|
7
|
+
http://code.google.com/p/keyczar/downloads/list
|
8
|
+
|
9
|
+
For now, we assume that keyczar-cpp was installed with the prefix
|
10
|
+
/usr/local.
|
11
|
+
|
12
|
+
Methods:
|
13
|
+
|
14
|
+
Keyczar::Crypter#encrypt(plaintext) #=> cryptext
|
15
|
+
Keyczar::Crypter#decrypt(cryptext) #=> plaintext
|
16
|
+
Keyczar::Signer#sign(text) #=> signature
|
17
|
+
Keyczar::Signer#verify(text,signature) #=> true or false
|
18
|
+
|
19
|
+
The first 3 return empty string on error. #encrypt and #sign results are
|
20
|
+
base64 encoded.
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# File: Rakefile
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/extensiontask'
|
5
|
+
|
6
|
+
load './keyczar_ruby.gemspec'
|
7
|
+
|
8
|
+
Gem::PackageTask.new($keyczar_ruby_gemspec)
|
9
|
+
|
10
|
+
Rake::ExtensionTask.new('keyczar_ruby') do |ext|
|
11
|
+
ext.source_pattern = "*.{c,cc}" # monitor file changes to allow simple rebuild.
|
12
|
+
ext.gem_spec = $keyczar_ruby_gemspec
|
13
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#include "keyczar/keyczar.h"
|
2
|
+
|
3
|
+
#include "ruby.h"
|
4
|
+
|
5
|
+
extern "C" {
|
6
|
+
static VALUE Keyczar = Qnil;
|
7
|
+
static VALUE Signer = Qnil;
|
8
|
+
static VALUE Crypter = Qnil;
|
9
|
+
|
10
|
+
static VALUE keyczar_signer_new(VALUE klass, VALUE location);
|
11
|
+
static VALUE keyczar_crypter_new(VALUE klass, VALUE location);
|
12
|
+
|
13
|
+
static VALUE keyczar_encrypt(VALUE self, VALUE plaintext);
|
14
|
+
static VALUE keyczar_decrypt(VALUE self, VALUE cryptext);
|
15
|
+
static VALUE keyczar_sign(VALUE self, VALUE text);
|
16
|
+
static VALUE keyczar_verify(VALUE self, VALUE text, VALUE signature);
|
17
|
+
|
18
|
+
void Init_keyczar_ruby() {
|
19
|
+
Keyczar = rb_define_module("Keyczar");
|
20
|
+
Signer = rb_define_class_under(Keyczar, "Signer", rb_cObject);
|
21
|
+
Crypter = rb_define_class_under(Keyczar, "Crypter", rb_cObject);
|
22
|
+
|
23
|
+
rb_define_method(Crypter, "encrypt", (VALUE (*)(...))keyczar_encrypt, 1);
|
24
|
+
rb_define_method(Crypter, "decrypt", (VALUE (*)(...))keyczar_decrypt, 1);
|
25
|
+
|
26
|
+
rb_define_method(Signer, "sign", (VALUE (*)(...))keyczar_sign, 1);
|
27
|
+
rb_define_method(Signer, "verify", (VALUE (*)(...))keyczar_verify, 2);
|
28
|
+
|
29
|
+
rb_define_singleton_method(Crypter, "new", (VALUE (*)(...))keyczar_crypter_new, 1);
|
30
|
+
rb_define_singleton_method(Signer, "new", (VALUE (*)(...))keyczar_signer_new, 1);
|
31
|
+
}
|
32
|
+
|
33
|
+
static void signer_free(keyczar::Signer *ptr){
|
34
|
+
delete ptr;
|
35
|
+
}
|
36
|
+
|
37
|
+
static void crypter_free(keyczar::Crypter *ptr){
|
38
|
+
delete ptr;
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE keyczar_signer_new(VALUE klass, VALUE location)
|
42
|
+
{
|
43
|
+
VALUE argv[1];
|
44
|
+
keyczar::Signer* ptr = keyczar::Signer::Read(RSTRING_PTR(location));
|
45
|
+
VALUE tdata = Data_Wrap_Struct(klass, 0, signer_free, ptr);
|
46
|
+
argv[0] = location;
|
47
|
+
rb_obj_call_init(tdata, 1, argv);
|
48
|
+
return tdata;
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE keyczar_crypter_new(VALUE klass, VALUE location)
|
52
|
+
{
|
53
|
+
VALUE argv[1];
|
54
|
+
keyczar::Crypter* ptr = keyczar::Crypter::Read(RSTRING_PTR(location));
|
55
|
+
VALUE tdata = Data_Wrap_Struct(klass, 0, crypter_free, ptr);
|
56
|
+
argv[0] = location;
|
57
|
+
rb_obj_call_init(tdata, 1, argv);
|
58
|
+
return tdata;
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE keyczar_encrypt(VALUE self, VALUE plaintext){
|
62
|
+
keyczar::Crypter* crypter;
|
63
|
+
Data_Get_Struct(self, keyczar::Crypter, crypter);
|
64
|
+
|
65
|
+
std::string cryptext=crypter->Encrypt(RSTRING_PTR(plaintext));
|
66
|
+
|
67
|
+
return rb_str_new2(cryptext.c_str());
|
68
|
+
}
|
69
|
+
|
70
|
+
static VALUE keyczar_decrypt(VALUE self, VALUE cryptext){
|
71
|
+
keyczar::Crypter* crypter;
|
72
|
+
Data_Get_Struct(self, keyczar::Crypter, crypter);
|
73
|
+
|
74
|
+
std::string plaintext=crypter->Decrypt(RSTRING_PTR(cryptext));
|
75
|
+
|
76
|
+
return rb_str_new2(plaintext.c_str());
|
77
|
+
}
|
78
|
+
|
79
|
+
static VALUE keyczar_sign(VALUE self, VALUE text){
|
80
|
+
keyczar::Signer* signer;
|
81
|
+
Data_Get_Struct(self, keyczar::Signer, signer);
|
82
|
+
|
83
|
+
std::string signature=signer->Sign(RSTRING_PTR(text));
|
84
|
+
|
85
|
+
return rb_str_new2(signature.c_str());
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE keyczar_verify(VALUE self, VALUE text, VALUE signature){
|
89
|
+
keyczar::Signer* signer;
|
90
|
+
Data_Get_Struct(self, keyczar::Signer, signer);
|
91
|
+
|
92
|
+
bool result=signer->Verify(RSTRING_PTR(text), RSTRING_PTR(signature));
|
93
|
+
|
94
|
+
return result ? Qtrue : Qfalse;
|
95
|
+
}
|
96
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "keyczar_ruby/version"
|
4
|
+
|
5
|
+
$keyczar_ruby_gemspec = Gem::Specification.new do |s|
|
6
|
+
s.name = %q{keyczar_ruby}
|
7
|
+
s.version = Keyczar::VERSION
|
8
|
+
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.authors = [%q{TrueCar SF Dev Team}]
|
11
|
+
s.date = %q{2012-08-31}
|
12
|
+
s.description = %q{ruby wrapper for keyczar crypto library}
|
13
|
+
s.email = %q{dev-sf@truecar.com}
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
|
+
s.extensions = ['ext/keyczar_ruby/extconf.rb']
|
17
|
+
# s.homepage = %q{http://clearbook.truecar.com}
|
18
|
+
s.require_paths = [%q{lib}]
|
19
|
+
s.rubygems_version = %q{1.8.9}
|
20
|
+
s.summary = %q{ruby wrapper for keyczar crypto library}
|
21
|
+
|
22
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.2"])
|
23
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
|
24
|
+
s.add_development_dependency(%q<rr>, [">= 0"])
|
25
|
+
s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
|
26
|
+
|
27
|
+
s.add_development_dependency(%q<rake-compiler>, ["~> 0.8.1"])
|
28
|
+
end
|
29
|
+
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keyczar_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- TrueCar SF Dev Team
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-08-31 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.1.2
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.7.0
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rr
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.9.2
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rake-compiler
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.1
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
description: ruby wrapper for keyczar crypto library
|
72
|
+
email: dev-sf@truecar.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions:
|
76
|
+
- ext/keyczar_ruby/extconf.rb
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- Gemfile
|
82
|
+
- README
|
83
|
+
- Rakefile
|
84
|
+
- ext/keyczar_ruby/extconf.rb
|
85
|
+
- ext/keyczar_ruby/keyczar_ruby.cc
|
86
|
+
- keyczar_ruby.gemspec
|
87
|
+
- lib/keyczar_ruby/version.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage:
|
90
|
+
licenses: []
|
91
|
+
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.5.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: ruby wrapper for keyczar crypto library
|
116
|
+
test_files: []
|
117
|
+
|