Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/resources/cryptotoken/b64.js

Issue 249913002: FIDO U2F component extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with HEAD Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // WebSafeBase64Escape and Unescape.
6 // mschilder@google.com
7 function B64_encode(bytes, opt_length) {
8 if (!opt_length) opt_length = bytes.length;
9 var b64out =
10 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
11 var result = '';
12 var shift = 0;
13 var accu = 0;
14 var input_index = 0;
15 while (opt_length--) {
16 accu <<= 8;
17 accu |= bytes[input_index++];
18 shift += 8;
19 while (shift >= 6) {
20 var i = (accu >> (shift - 6)) & 63;
21 result += b64out.charAt(i);
22 shift -= 6;
23 }
24 }
25 if (shift) {
26 accu <<= 8;
27 shift += 8;
28 var i = (accu >> (shift - 6)) & 63;
29 result += b64out.charAt(i);
30 }
31 return result;
32 }
33
34 // Normal base64 encode; not websafe, including padding.
35 function base64_encode(bytes, opt_length) {
36 if (!opt_length) opt_length = bytes.length;
37 var b64out =
38 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
39 var result = '';
40 var shift = 0;
41 var accu = 0;
42 var input_index = 0;
43 while (opt_length--) {
44 accu <<= 8;
45 accu |= bytes[input_index++];
46 shift += 8;
47 while (shift >= 6) {
48 var i = (accu >> (shift - 6)) & 63;
49 result += b64out.charAt(i);
50 shift -= 6;
51 }
52 }
53 if (shift) {
54 accu <<= 8;
55 shift += 8;
56 var i = (accu >> (shift - 6)) & 63;
57 result += b64out.charAt(i);
58 }
59 while (result.length % 4) result += '=';
60 return result;
61 }
62
63 var B64_inmap =
64 [
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0,
66 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 0, 0, 0, 0, 0, 0,
67 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
68 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 0, 0, 0, 64,
69 0, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
70 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 0, 0, 0, 0, 0
71 ];
72
73 function B64_decode(string) {
74 var bytes = [];
75 var accu = 0;
76 var shift = 0;
77 for (var i = 0; i < string.length; ++i) {
78 var c = string.charCodeAt(i);
79 if (c < 32 || c > 127 || !B64_inmap[c - 32]) return [];
80 accu <<= 6;
81 accu |= (B64_inmap[c - 32] - 1);
82 shift += 6;
83 if (shift >= 8) {
84 bytes.push((accu >> (shift - 8)) & 255);
85 shift -= 8;
86 }
87 }
88 return bytes;
89 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/component_extension_resources.grd ('k') | chrome/browser/resources/cryptotoken/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698