blackbox 3.2.0 → 3.3.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/blackbox.gemspec +4 -3
- data/coverage/.last_run.json +1 -1
- data/coverage/.resultset.json +62 -19
- data/coverage/index.html +538 -280
- data/doc/BB.html +2 -2
- data/doc/BB/Crypto.html +30 -20
- data/doc/BB/Crypto/ControlToken.html +529 -0
- data/doc/BB/Gem.html +1 -1
- data/doc/BB/Hash.html +1 -1
- data/doc/BB/Number.html +9 -11
- data/doc/BB/String.html +1 -1
- data/doc/BB/Unix.html +1 -1
- data/doc/_index.html +8 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +18 -6
- data/doc/top-level-namespace.html +1 -1
- data/lib/blackbox/crypto.rb +45 -1
- data/lib/blackbox/number.rb +1 -2
- data/lib/blackbox/version.rb +1 -1
- data/spec/crypto_spec.rb +49 -9
- metadata +29 -14
data/doc/BB.html
CHANGED
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
<dt id="VERSION-constant" class="">VERSION =
|
|
116
116
|
|
|
117
117
|
</dt>
|
|
118
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>3.
|
|
118
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>3.3.0</span><span class='tstring_end'>'</span></span></pre></dd>
|
|
119
119
|
|
|
120
120
|
</dl>
|
|
121
121
|
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
</div>
|
|
132
132
|
|
|
133
133
|
<div id="footer">
|
|
134
|
-
Generated on
|
|
134
|
+
Generated on Sat Jul 30 17:08:30 2016 by
|
|
135
135
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
136
136
|
0.8.7.6 (ruby-2.3.1).
|
|
137
137
|
</div>
|
data/doc/BB/Crypto.html
CHANGED
|
@@ -95,7 +95,17 @@
|
|
|
95
95
|
<div class="tags">
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
</div>
|
|
98
|
+
</div><h2>Defined Under Namespace</h2>
|
|
99
|
+
<p class="children">
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Crypto/ControlToken.html" title="BB::Crypto::ControlToken (class)">ControlToken</a></span>
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
</p>
|
|
108
|
+
|
|
99
109
|
|
|
100
110
|
|
|
101
111
|
|
|
@@ -379,7 +389,6 @@
|
|
|
379
389
|
<pre class="lines">
|
|
380
390
|
|
|
381
391
|
|
|
382
|
-
37
|
|
383
392
|
38
|
|
384
393
|
39
|
|
385
394
|
40
|
|
@@ -390,10 +399,11 @@
|
|
|
390
399
|
45
|
|
391
400
|
46
|
|
392
401
|
47
|
|
393
|
-
48
|
|
402
|
+
48
|
|
403
|
+
49</pre>
|
|
394
404
|
</td>
|
|
395
405
|
<td>
|
|
396
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line
|
|
406
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 38</span>
|
|
397
407
|
|
|
398
408
|
<span class='kw'>def</span> <span class='id identifier rubyid_decrypt'>decrypt</span><span class='lparen'>(</span><span class='id identifier rubyid_ciphertext'>ciphertext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
399
409
|
<span class='id identifier rubyid_cipher'>cipher</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Cipher</span><span class='op'>::</span><span class='const'>Cipher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='rparen'>)</span>
|
|
@@ -528,12 +538,12 @@
|
|
|
528
538
|
<pre class="lines">
|
|
529
539
|
|
|
530
540
|
|
|
531
|
-
69
|
|
532
541
|
70
|
|
533
|
-
71
|
|
542
|
+
71
|
|
543
|
+
72</pre>
|
|
534
544
|
</td>
|
|
535
545
|
<td>
|
|
536
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line
|
|
546
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 70</span>
|
|
537
547
|
|
|
538
548
|
<span class='kw'>def</span> <span class='id identifier rubyid_decrypt_base64'>decrypt_base64</span><span class='lparen'>(</span><span class='id identifier rubyid_ciphertext'>ciphertext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
539
549
|
<span class='id identifier rubyid_decrypt'>decrypt</span><span class='lparen'>(</span><span class='const'>Base64</span><span class='period'>.</span><span class='id identifier rubyid_decode64'>decode64</span><span class='lparen'>(</span><span class='id identifier rubyid_ciphertext'>ciphertext</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span><span class='rparen'>)</span>
|
|
@@ -659,12 +669,12 @@
|
|
|
659
669
|
<pre class="lines">
|
|
660
670
|
|
|
661
671
|
|
|
662
|
-
92
|
|
663
672
|
93
|
|
664
|
-
94
|
|
673
|
+
94
|
|
674
|
+
95</pre>
|
|
665
675
|
</td>
|
|
666
676
|
<td>
|
|
667
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line
|
|
677
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 93</span>
|
|
668
678
|
|
|
669
679
|
<span class='kw'>def</span> <span class='id identifier rubyid_decrypt_urlsafe_base64'>decrypt_urlsafe_base64</span><span class='lparen'>(</span><span class='id identifier rubyid_ciphertext'>ciphertext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
670
680
|
<span class='id identifier rubyid_decrypt'>decrypt</span><span class='lparen'>(</span><span class='const'>Base64</span><span class='period'>.</span><span class='id identifier rubyid_urlsafe_decode64'>urlsafe_decode64</span><span class='lparen'>(</span><span class='id identifier rubyid_ciphertext'>ciphertext</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span><span class='rparen'>)</span>
|
|
@@ -804,7 +814,6 @@
|
|
|
804
814
|
<pre class="lines">
|
|
805
815
|
|
|
806
816
|
|
|
807
|
-
17
|
|
808
817
|
18
|
|
809
818
|
19
|
|
810
819
|
20
|
|
@@ -815,10 +824,11 @@
|
|
|
815
824
|
25
|
|
816
825
|
26
|
|
817
826
|
27
|
|
818
|
-
28
|
|
827
|
+
28
|
|
828
|
+
29</pre>
|
|
819
829
|
</td>
|
|
820
830
|
<td>
|
|
821
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line
|
|
831
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 18</span>
|
|
822
832
|
|
|
823
833
|
<span class='kw'>def</span> <span class='id identifier rubyid_encrypt'>encrypt</span><span class='lparen'>(</span><span class='id identifier rubyid_plaintext'>plaintext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
824
834
|
<span class='id identifier rubyid_cipher'>cipher</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Cipher</span><span class='op'>::</span><span class='const'>Cipher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='rparen'>)</span>
|
|
@@ -967,12 +977,12 @@
|
|
|
967
977
|
<pre class="lines">
|
|
968
978
|
|
|
969
979
|
|
|
970
|
-
58
|
|
971
980
|
59
|
|
972
|
-
60
|
|
981
|
+
60
|
|
982
|
+
61</pre>
|
|
973
983
|
</td>
|
|
974
984
|
<td>
|
|
975
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line
|
|
985
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 59</span>
|
|
976
986
|
|
|
977
987
|
<span class='kw'>def</span> <span class='id identifier rubyid_encrypt_base64'>encrypt_base64</span><span class='lparen'>(</span><span class='id identifier rubyid_plaintext'>plaintext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
978
988
|
<span class='const'>Base64</span><span class='period'>.</span><span class='id identifier rubyid_strict_encode64'>strict_encode64</span><span class='lparen'>(</span><span class='id identifier rubyid_encrypt'>encrypt</span><span class='lparen'>(</span><span class='id identifier rubyid_plaintext'>plaintext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
@@ -1112,12 +1122,12 @@
|
|
|
1112
1122
|
<pre class="lines">
|
|
1113
1123
|
|
|
1114
1124
|
|
|
1115
|
-
81
|
|
1116
1125
|
82
|
|
1117
|
-
83
|
|
1126
|
+
83
|
|
1127
|
+
84</pre>
|
|
1118
1128
|
</td>
|
|
1119
1129
|
<td>
|
|
1120
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line
|
|
1130
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 82</span>
|
|
1121
1131
|
|
|
1122
1132
|
<span class='kw'>def</span> <span class='id identifier rubyid_encrypt_urlsafe_base64'>encrypt_urlsafe_base64</span><span class='lparen'>(</span><span class='id identifier rubyid_plaintext'>plaintext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
1123
1133
|
<span class='const'>Base64</span><span class='period'>.</span><span class='id identifier rubyid_urlsafe_encode64'>urlsafe_encode64</span><span class='lparen'>(</span><span class='id identifier rubyid_encrypt'>encrypt</span><span class='lparen'>(</span><span class='id identifier rubyid_plaintext'>plaintext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
@@ -1132,7 +1142,7 @@
|
|
|
1132
1142
|
</div>
|
|
1133
1143
|
|
|
1134
1144
|
<div id="footer">
|
|
1135
|
-
Generated on
|
|
1145
|
+
Generated on Sat Jul 30 17:08:31 2016 by
|
|
1136
1146
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
1137
1147
|
0.8.7.6 (ruby-2.3.1).
|
|
1138
1148
|
</div>
|
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
6
|
+
<title>
|
|
7
|
+
Class: BB::Crypto::ControlToken
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.8.7.6
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
|
19
|
+
relpath = '../../';
|
|
20
|
+
framesUrl = "../../frames.html#!BB/Crypto/ControlToken.html";
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
|
|
25
|
+
|
|
26
|
+
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<div id="header">
|
|
32
|
+
<div id="menu">
|
|
33
|
+
|
|
34
|
+
<a href="../../_index.html">Index (C)</a> »
|
|
35
|
+
<span class='title'><span class='object_link'><a href="../../BB.html" title="BB (module)">BB</a></span></span> » <span class='title'><span class='object_link'><a href="../Crypto.html" title="BB::Crypto (module)">Crypto</a></span></span>
|
|
36
|
+
»
|
|
37
|
+
<span class="title">ControlToken</span>
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div id="search">
|
|
44
|
+
|
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
|
46
|
+
href="../../class_list.html">
|
|
47
|
+
Class List
|
|
48
|
+
</a>
|
|
49
|
+
|
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
|
51
|
+
href="../../method_list.html">
|
|
52
|
+
Method List
|
|
53
|
+
</a>
|
|
54
|
+
|
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
|
56
|
+
href="../../file_list.html">
|
|
57
|
+
File List
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
<div class="clear"></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<iframe id="search_frame"></iframe>
|
|
65
|
+
|
|
66
|
+
<div id="content"><h1>Class: BB::Crypto::ControlToken
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
</h1>
|
|
71
|
+
|
|
72
|
+
<dl class="box">
|
|
73
|
+
|
|
74
|
+
<dt class="r1">Inherits:</dt>
|
|
75
|
+
<dd class="r1">
|
|
76
|
+
<span class="inheritName">Object</span>
|
|
77
|
+
|
|
78
|
+
<ul class="fullTree">
|
|
79
|
+
<li>Object</li>
|
|
80
|
+
|
|
81
|
+
<li class="next">BB::Crypto::ControlToken</li>
|
|
82
|
+
|
|
83
|
+
</ul>
|
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
|
85
|
+
|
|
86
|
+
</dd>
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
<dt class="r2 last">Defined in:</dt>
|
|
97
|
+
<dd class="r2 last">lib/blackbox/crypto.rb</dd>
|
|
98
|
+
|
|
99
|
+
</dl>
|
|
100
|
+
<div class="clear"></div>
|
|
101
|
+
|
|
102
|
+
<h2>Overview</h2><div class="docstring">
|
|
103
|
+
<div class="discussion">
|
|
104
|
+
|
|
105
|
+
<p>Secure Control Token.</p>
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
<div class="tags">
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
<h2>
|
|
122
|
+
Class Method Summary
|
|
123
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
|
124
|
+
</h2>
|
|
125
|
+
|
|
126
|
+
<ul class="summary">
|
|
127
|
+
|
|
128
|
+
<li class="public ">
|
|
129
|
+
<span class="summary_signature">
|
|
130
|
+
|
|
131
|
+
<a href="#create-class_method" title="create (class method)">+ (String) <strong>create</strong>(op, args, expire_in = 900, key = ENV['CONTROLTOKEN_SECRET'], cipher_type = 'aes-256-cbc') </a>
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
</span>
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
<span class="summary_desc"><div class='inline'>
|
|
146
|
+
<p>Encode and encrypt an urlsafe ControlToken.</p>
|
|
147
|
+
</div></span>
|
|
148
|
+
|
|
149
|
+
</li>
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
<li class="public ">
|
|
153
|
+
<span class="summary_signature">
|
|
154
|
+
|
|
155
|
+
<a href="#parse-class_method" title="parse (class method)">+ (Hash) <strong>parse</strong>(token, key = ENV['CONTROLTOKEN_SECRET'], force = false, cipher_type = 'aes-256-cbc') </a>
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
</span>
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
<span class="summary_desc"><div class='inline'>
|
|
170
|
+
<p>Decrypt and parse an urlsafe ControlToken.</p>
|
|
171
|
+
</div></span>
|
|
172
|
+
|
|
173
|
+
</li>
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
</ul>
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
<div id="class_method_details" class="method_details_list">
|
|
182
|
+
<h2>Class Method Details</h2>
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
<div class="method_details first">
|
|
186
|
+
<h3 class="signature first" id="create-class_method">
|
|
187
|
+
|
|
188
|
+
+ (<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>) <strong>create</strong>(op, args, expire_in = 900, key = ENV['CONTROLTOKEN_SECRET'], cipher_type = 'aes-256-cbc')
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
</h3><div class="docstring">
|
|
195
|
+
<div class="discussion">
|
|
196
|
+
|
|
197
|
+
<p>Encode and encrypt an urlsafe ControlToken.</p>
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
<div class="tags">
|
|
203
|
+
<p class="tag_title">Parameters:</p>
|
|
204
|
+
<ul class="param">
|
|
205
|
+
|
|
206
|
+
<li>
|
|
207
|
+
|
|
208
|
+
<span class='name'>op</span>
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>)</span>
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
—
|
|
216
|
+
<div class='inline'>
|
|
217
|
+
<p>Operation id</p>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
</li>
|
|
221
|
+
|
|
222
|
+
<li>
|
|
223
|
+
|
|
224
|
+
<span class='name'>args</span>
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
<span class='type'>(<tt>Array</tt>)</span>
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
—
|
|
232
|
+
<div class='inline'>
|
|
233
|
+
<p>Arguments (Strings)</p>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
</li>
|
|
237
|
+
|
|
238
|
+
<li>
|
|
239
|
+
|
|
240
|
+
<span class='name'>expire_in</span>
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
<span class='type'>(<tt>Fixnum</tt>)</span>
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
<em class="default">(defaults to: <tt>900</tt>)</em>
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
</li>
|
|
250
|
+
|
|
251
|
+
<li>
|
|
252
|
+
|
|
253
|
+
<span class='name'>key</span>
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>)</span>
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
<em class="default">(defaults to: <tt>ENV['CONTROLTOKEN_SECRET']</tt>)</em>
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
—
|
|
263
|
+
<div class='inline'>
|
|
264
|
+
<p>Encryption key</p>
|
|
265
|
+
</div>
|
|
266
|
+
|
|
267
|
+
</li>
|
|
268
|
+
|
|
269
|
+
<li>
|
|
270
|
+
|
|
271
|
+
<span class='name'>cipher_type</span>
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>)</span>
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
<em class="default">(defaults to: <tt>'aes-256-cbc'</tt>)</em>
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
—
|
|
281
|
+
<div class='inline'>
|
|
282
|
+
<p>OpenSSL cipher</p>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
</li>
|
|
286
|
+
|
|
287
|
+
</ul>
|
|
288
|
+
|
|
289
|
+
<p class="tag_title">Returns:</p>
|
|
290
|
+
<ul class="return">
|
|
291
|
+
|
|
292
|
+
<li>
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>)</span>
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
—
|
|
300
|
+
<div class='inline'>
|
|
301
|
+
<p>ControlToken (urlsafe base64)</p>
|
|
302
|
+
</div>
|
|
303
|
+
|
|
304
|
+
</li>
|
|
305
|
+
|
|
306
|
+
</ul>
|
|
307
|
+
<p class="tag_title">Raises:</p>
|
|
308
|
+
<ul class="raise">
|
|
309
|
+
|
|
310
|
+
<li>
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
</li>
|
|
318
|
+
|
|
319
|
+
</ul>
|
|
320
|
+
|
|
321
|
+
</div><table class="source_code">
|
|
322
|
+
<tr>
|
|
323
|
+
<td>
|
|
324
|
+
<pre class="lines">
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
109
|
|
328
|
+
110
|
|
329
|
+
111
|
|
330
|
+
112
|
|
331
|
+
113
|
|
332
|
+
114
|
|
333
|
+
115</pre>
|
|
334
|
+
</td>
|
|
335
|
+
<td>
|
|
336
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 109</span>
|
|
337
|
+
|
|
338
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_op'>op</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_expire_in'>expire_in</span> <span class='op'>=</span> <span class='int'>900</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>CONTROLTOKEN_SECRET</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
339
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>key can not be blank</span><span class='tstring_end'>'</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>||</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
|
340
|
+
<span class='comment'># If you're reading this in the year 2038: Hi there! :-)
|
|
341
|
+
</span> <span class='lbracket'>[</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='op'>+</span> <span class='id identifier rubyid_expire_in'>expire_in</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_pack'>pack</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>l<</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
342
|
+
<span class='id identifier rubyid_body'>body</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='lbracket'>[</span><span class='lbracket'>[</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='op'>+</span> <span class='id identifier rubyid_expire_in'>expire_in</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_pack'>pack</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>l<</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_op'>op</span><span class='rbracket'>]</span> <span class='op'>+</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\x00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
343
|
+
<span class='const'>BB</span><span class='op'>::</span><span class='const'>Crypto</span><span class='period'>.</span><span class='id identifier rubyid_encrypt_urlsafe_base64'>encrypt_urlsafe_base64</span><span class='lparen'>(</span><span class='id identifier rubyid_body'>body</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='rparen'>)</span>
|
|
344
|
+
<span class='kw'>end</span></pre>
|
|
345
|
+
</td>
|
|
346
|
+
</tr>
|
|
347
|
+
</table>
|
|
348
|
+
</div>
|
|
349
|
+
|
|
350
|
+
<div class="method_details ">
|
|
351
|
+
<h3 class="signature " id="parse-class_method">
|
|
352
|
+
|
|
353
|
+
+ (<tt><span class='object_link'><a href="../Hash.html" title="BB::Hash (module)">Hash</a></span></tt>) <strong>parse</strong>(token, key = ENV['CONTROLTOKEN_SECRET'], force = false, cipher_type = 'aes-256-cbc')
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
</h3><div class="docstring">
|
|
360
|
+
<div class="discussion">
|
|
361
|
+
|
|
362
|
+
<p>Decrypt and parse an urlsafe ControlToken.</p>
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
<div class="tags">
|
|
368
|
+
<p class="tag_title">Parameters:</p>
|
|
369
|
+
<ul class="param">
|
|
370
|
+
|
|
371
|
+
<li>
|
|
372
|
+
|
|
373
|
+
<span class='name'>token</span>
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>)</span>
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
—
|
|
381
|
+
<div class='inline'>
|
|
382
|
+
<p>Input String (urlsafe base64)</p>
|
|
383
|
+
</div>
|
|
384
|
+
|
|
385
|
+
</li>
|
|
386
|
+
|
|
387
|
+
<li>
|
|
388
|
+
|
|
389
|
+
<span class='name'>key</span>
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>)</span>
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
<em class="default">(defaults to: <tt>ENV['CONTROLTOKEN_SECRET']</tt>)</em>
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
—
|
|
399
|
+
<div class='inline'>
|
|
400
|
+
<p>Encryption key</p>
|
|
401
|
+
</div>
|
|
402
|
+
|
|
403
|
+
</li>
|
|
404
|
+
|
|
405
|
+
<li>
|
|
406
|
+
|
|
407
|
+
<span class='name'>force</span>
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
<em class="default">(defaults to: <tt>false</tt>)</em>
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
—
|
|
417
|
+
<div class='inline'>
|
|
418
|
+
<p>Decode expired token (suppress ArgumentError)</p>
|
|
419
|
+
</div>
|
|
420
|
+
|
|
421
|
+
</li>
|
|
422
|
+
|
|
423
|
+
<li>
|
|
424
|
+
|
|
425
|
+
<span class='name'>cipher_type</span>
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="BB::String (module)">String</a></span></tt>)</span>
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
<em class="default">(defaults to: <tt>'aes-256-cbc'</tt>)</em>
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
—
|
|
435
|
+
<div class='inline'>
|
|
436
|
+
<p>OpenSSL cipher</p>
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
</li>
|
|
440
|
+
|
|
441
|
+
</ul>
|
|
442
|
+
|
|
443
|
+
<p class="tag_title">Returns:</p>
|
|
444
|
+
<ul class="return">
|
|
445
|
+
|
|
446
|
+
<li>
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
<span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="BB::Hash (module)">Hash</a></span></tt>)</span>
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
—
|
|
454
|
+
<div class='inline'>
|
|
455
|
+
<p>Token payload</p>
|
|
456
|
+
</div>
|
|
457
|
+
|
|
458
|
+
</li>
|
|
459
|
+
|
|
460
|
+
</ul>
|
|
461
|
+
<p class="tag_title">Raises:</p>
|
|
462
|
+
<ul class="raise">
|
|
463
|
+
|
|
464
|
+
<li>
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
</li>
|
|
472
|
+
|
|
473
|
+
</ul>
|
|
474
|
+
|
|
475
|
+
</div><table class="source_code">
|
|
476
|
+
<tr>
|
|
477
|
+
<td>
|
|
478
|
+
<pre class="lines">
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
124
|
|
482
|
+
125
|
|
483
|
+
126
|
|
484
|
+
127
|
|
485
|
+
128
|
|
486
|
+
129
|
|
487
|
+
130
|
|
488
|
+
131
|
|
489
|
+
132
|
|
490
|
+
133
|
|
491
|
+
134
|
|
492
|
+
135
|
|
493
|
+
136
|
|
494
|
+
137</pre>
|
|
495
|
+
</td>
|
|
496
|
+
<td>
|
|
497
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 124</span>
|
|
498
|
+
|
|
499
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>CONTROLTOKEN_SECRET</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_force'>force</span> <span class='op'>=</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
500
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>key can not be blank</span><span class='tstring_end'>'</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>||</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
|
501
|
+
<span class='id identifier rubyid_body'>body</span> <span class='op'>=</span> <span class='const'>BB</span><span class='op'>::</span><span class='const'>Crypto</span><span class='period'>.</span><span class='id identifier rubyid_decrypt_urlsafe_base64'>decrypt_urlsafe_base64</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='rparen'>)</span>
|
|
502
|
+
<span class='id identifier rubyid_valid_until'>valid_until</span><span class='comma'>,</span> <span class='id identifier rubyid_op'>op</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='id identifier rubyid_body'>body</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\x00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
503
|
+
<span class='id identifier rubyid_valid_until'>valid_until</span> <span class='op'>=</span> <span class='id identifier rubyid_valid_until'>valid_until</span><span class='period'>.</span><span class='id identifier rubyid_unpack'>unpack</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>l<</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
|
504
|
+
<span class='id identifier rubyid_expired'>expired</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='op'>></span> <span class='id identifier rubyid_valid_until'>valid_until</span>
|
|
505
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_expired'>expired</span> <span class='op'>&&</span> <span class='op'>!</span><span class='id identifier rubyid_force'>force</span>
|
|
506
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Token expired at </span><span class='embexpr_beg'>#{</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_at'>at</span><span class='lparen'>(</span><span class='id identifier rubyid_valid_until'>valid_until</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_content'> (</span><span class='embexpr_beg'>#{</span><span class='const'>ChronicDuration</span><span class='period'>.</span><span class='id identifier rubyid_output'>output</span><span class='lparen'>(</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='op'>-</span> <span class='id identifier rubyid_valid_until'>valid_until</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_content'> ago)</span><span class='tstring_end'>"</span></span>
|
|
507
|
+
<span class='kw'>end</span>
|
|
508
|
+
<span class='lbrace'>{</span> <span class='label'>valid_until:</span> <span class='id identifier rubyid_valid_until'>valid_until</span><span class='comma'>,</span>
|
|
509
|
+
<span class='label'>op:</span> <span class='id identifier rubyid_op'>op</span><span class='comma'>,</span>
|
|
510
|
+
<span class='label'>args:</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span>
|
|
511
|
+
<span class='label'>expired:</span> <span class='id identifier rubyid_expired'>expired</span> <span class='rbrace'>}</span>
|
|
512
|
+
<span class='kw'>end</span></pre>
|
|
513
|
+
</td>
|
|
514
|
+
</tr>
|
|
515
|
+
</table>
|
|
516
|
+
</div>
|
|
517
|
+
|
|
518
|
+
</div>
|
|
519
|
+
|
|
520
|
+
</div>
|
|
521
|
+
|
|
522
|
+
<div id="footer">
|
|
523
|
+
Generated on Sat Jul 30 17:08:31 2016 by
|
|
524
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
525
|
+
0.8.7.6 (ruby-2.3.1).
|
|
526
|
+
</div>
|
|
527
|
+
|
|
528
|
+
</body>
|
|
529
|
+
</html>
|