Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch nmadden-json-web-token
Excluding Merge-Ins
This is equivalent to a diff from
d9d86cd9ff
to 783e8f3bf8
2014-11-27
| | |
01:09 |
|
check-in: e4cc97ecc8 user: aku tags: trunk
|
00:04 |
|
check-in: e3bc24a81e user: andreask tags: ak-fix-traverse-symlinks
|
2014-11-25
| | |
14:50 |
|
Leaf
check-in: 783e8f3bf8 user: neilmadden tags: nmadden-json-web-token
|
2014-11-19
| | |
04:49 |
|
check-in: 24cd9d7b26 user: aku tags: nettool
|
04:29 |
|
check-in: d9d86cd9ff user: aku tags: trunk
|
01:09 |
|
check-in: 262292fc92 user: andreask tags: trunk
|
2014-11-14
| | |
23:34 |
|
Closed-Leaf
check-in: e08de35f0a user: pooryorick tags: pyk-withtclsh-ba3b0d91
|
| | |
Added modules/base64url/base64url.man.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
[manpage_begin base64url n 1.0]
[keywords base64url]
[keywords base64]
[keywords encoding]
[copyright {2014, Neil Madden}]
[moddesc {URL-safe text encoding & decoding binary data}]
[titledesc {base64url-encode/decode binary data}]
[category {Text processing}]
[require Tcl 8.5]
[require base64url [opt 1.0]]
[description]
[para]
This package provides procedures to encode binary data into URL-safe base64
and back. This is identical to Base64 encoding, except that no wrapping is
performed, the "+" and "/" characters are replaced by "-" and "_" respectively,
and no padding characters are appended.
[list_begin definitions]
[call [cmd {::base64url encode}] [arg encoding] [arg data]]
Base64url encodes the given [arg data] string and returns the encoded
result. The [arg data] string is first converted into binary data
using the given [arg encoding], as if by [cmd {encoding convertto}] [arg encoding].
If [arg encoding] is "binary" then no conversion is done.
[para]
The command will throw an error if the encoding is not recognised.
[call [cmd {::base64url decode}] [arg encoding] [arg data]]
Base64url decodes the given [arg data] and returns the decoded data.
The returned data is converted into a string according to the
[arg encoding], as if by [cmd {encoding convertfrom}] [arg encoding].
If [arg encoding] is "binary" then no conversion is done.
[list_end]
[section {EXAMPLES}]
[example {
% base64url encode utf-8 "Hello, world!"
SGVsbG8sIHdvcmxkIQ
}]
[example {
% base64url encode binary [binary format c* {1 2 3 4 5}]
AQIDBAU
% binary scan [base64url decode binary AQIDBAU] c* xs
1
% set xs
1 2 3 4 5
}]
[vset CATEGORY base64url]
[include ../doctools2base/include/feedback.inc]
[manpage_end]
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added modules/base64url/base64url.tcl.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
# base64url.tcl --
#
# Provides encode/decode routines for the 'base64url' encoding standard.
# See: http://tools.ietf.org/html/rfc4648#section-5
# We implement the version without padding as described here:
# https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#appendix-C
#
# Copyright (c) 2014 Neil Madden.
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
package require Tcl 8.5
package require base64 2.4
package provide base64url 1.0
namespace eval ::base64url {
namespace export encode decode
namespace ensemble create
# ::base64url encode encoding data --
#
# Base64url encode a given string.
#
# Arguments:
# encoding The character encoding to use when converting the string
# bytes. Use "binary" if already encoded.
# data The data to encode.
#
# Results:
# A base6url encoded version of $data in $encoding encoding.
#
proc encode {encoding data} {
if {$encoding ne "binary"} {
set data [encoding convertto $encoding $data]
}
string map {
+ -
/ _
= ""
} [base64::encode -wrapchar "" $data]
}
# :base64url decode encoding data --
#
# Base64url decode a given string.
#
# Arguments:
# encoding The character encoding to apply to the data after
# decoding. Use "binary" if data is binary.
# data The data to decode. Should be in base64url format.
#
# Results:
# The decoded data after conversion to the given character encoding.
#
proc decode {encoding data} {
set data [base64::decode [string map {
- +
_ /
} [pad-align 4 "=" $data]]]
if {$encoding ne "binary"} {
set data [encoding convertfrom $encoding $data]
}
return $data
}
# pad-align width padChar data --
#
# Right-pads $data with $padChar until it is a multiple of $width
# characters in length.
#
proc pad-align {width padChar data} {
append data [string repeat $padChar \
[expr {$width - ([string length $data] % $width)}]]
}
}
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added modules/base64url/base64url.test.