| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * SHA-1. | 6 * SHA-1. |
| 7 * Ripped from package:crypto. | 7 * Ripped from package:crypto. |
| 8 */ | 8 */ |
| 9 library sha1; | 9 library sha1; |
| 10 | 10 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 static const int CR = 13; // '\r' | 310 static const int CR = 13; // '\r' |
| 311 static const int LF = 10; // '\n' | 311 static const int LF = 10; // '\n' |
| 312 static const int LINE_LENGTH = 76; | 312 static const int LINE_LENGTH = 76; |
| 313 | 313 |
| 314 static const String _encodeTable = | 314 static const String _encodeTable = |
| 315 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | 315 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 316 | 316 |
| 317 static const String _encodeTableUrlSafe = | 317 static const String _encodeTableUrlSafe = |
| 318 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | 318 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; |
| 319 | 319 |
| 320 // Lookup table used for finding Base 64 alphabet index of a given byte. | |
| 321 // -2 : Outside Base 64 alphabet. | |
| 322 // -1 : '\r' or '\n' | |
| 323 // 0 : = (Padding character). | |
| 324 // >0 : Base 64 alphabet index of given byte. | |
| 325 static const List<int> _decodeTable = | |
| 326 const [ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2, | |
| 327 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 328 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, | |
| 329 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, 0, -2, -2, | |
| 330 -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | |
| 331 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, 63, | |
| 332 -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | |
| 333 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, | |
| 334 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 335 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 336 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 337 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 338 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 339 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 340 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | |
| 341 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 ]; | |
| 342 | |
| 343 static String bytesToBase64(List<int> bytes, | 320 static String bytesToBase64(List<int> bytes, |
| 344 [bool urlSafe = false, | 321 [bool urlSafe = false, |
| 345 bool addLineSeparator = false]) { | 322 bool addLineSeparator = false]) { |
| 346 int len = bytes.length; | 323 int len = bytes.length; |
| 347 if (len == 0) { | 324 if (len == 0) { |
| 348 return ""; | 325 return ""; |
| 349 } | 326 } |
| 350 final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable; | 327 final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable; |
| 351 // Size of 24 bit chunks. | 328 // Size of 24 bit chunks. |
| 352 final int remainderLength = len.remainder(3); | 329 final int remainderLength = len.remainder(3); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 int y = bytes[i + 1]; | 367 int y = bytes[i + 1]; |
| 391 out[j++] = lookup.codeUnitAt(x >> 2); | 368 out[j++] = lookup.codeUnitAt(x >> 2); |
| 392 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F); | 369 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F); |
| 393 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F); | 370 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F); |
| 394 out[j++] = PAD; | 371 out[j++] = PAD; |
| 395 } | 372 } |
| 396 | 373 |
| 397 return new String.fromCharCodes(out); | 374 return new String.fromCharCodes(out); |
| 398 } | 375 } |
| 399 } | 376 } |
| OLD | NEW |