| 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 part of dart.crypto; | 5 part of dart.crypto; |
| 6 | 6 |
| 7 class _LineWrappingStringBuffer { | 7 class _LineWrappingStringBuffer { |
| 8 _LineWrappingStringBuffer(int this._lineLength) : _sb = new StringBuffer(); | 8 _LineWrappingStringBuffer(int this._lineLength) : _sb = new StringBuffer(); |
| 9 | 9 |
| 10 void add(String s) { | 10 void add(String s) { |
| 11 if (_lineLength != null && _currentLineLength == _lineLength) { | 11 if (_lineLength != null && _currentLineLength == _lineLength) { |
| 12 _sb.add('\r\n'); | 12 _sb.write('\r\n'); |
| 13 _currentLineLength = 0; | 13 _currentLineLength = 0; |
| 14 } | 14 } |
| 15 _sb.add(s); | 15 _sb.write(s); |
| 16 _currentLineLength++; | 16 _currentLineLength++; |
| 17 } | 17 } |
| 18 | 18 |
| 19 String toString() => _sb.toString(); | 19 String toString() => _sb.toString(); |
| 20 | 20 |
| 21 int _lineLength; | 21 int _lineLength; |
| 22 StringBuffer _sb; | 22 StringBuffer _sb; |
| 23 int _currentLineLength = 0; | 23 int _currentLineLength = 0; |
| 24 } | 24 } |
| 25 | 25 |
| 26 abstract class _CryptoUtils { | 26 abstract class _CryptoUtils { |
| 27 static String bytesToHex(List<int> bytes) { | 27 static String bytesToHex(List<int> bytes) { |
| 28 var result = new StringBuffer(); | 28 var result = new StringBuffer(); |
| 29 for (var part in bytes) { | 29 for (var part in bytes) { |
| 30 result.add('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); | 30 result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); |
| 31 } | 31 } |
| 32 return result.toString(); | 32 return result.toString(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 static String bytesToBase64(List<int> bytes, [int lineLength]) { | 35 static String bytesToBase64(List<int> bytes, [int lineLength]) { |
| 36 final table = | 36 final table = |
| 37 const [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', | 37 const [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', |
| 38 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', | 38 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', |
| 39 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', | 39 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', |
| 40 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', | 40 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', |
| (...skipping 26 matching lines...) Expand all Loading... |
| 67 var b1 = bytes[i + 1] & 0xff; | 67 var b1 = bytes[i + 1] & 0xff; |
| 68 result.add(table[b0 >> 2]); | 68 result.add(table[b0 >> 2]); |
| 69 result.add(table[((b0 << 4) | (b1 >> 4)) & 0x3f]); | 69 result.add(table[((b0 << 4) | (b1 >> 4)) & 0x3f]); |
| 70 result.add(table[(b1 << 2) & 0x3f]); | 70 result.add(table[(b1 << 2) & 0x3f]); |
| 71 result.add('='); | 71 result.add('='); |
| 72 } | 72 } |
| 73 | 73 |
| 74 return result.toString(); | 74 return result.toString(); |
| 75 } | 75 } |
| 76 } | 76 } |
| OLD | NEW |