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 class _LineWrappingStringBuffer { | 5 class _LineWrappingStringBuffer { |
6 _LineWrappingStringBuffer(int this._lineLength) : _sb = new StringBuffer(); | 6 _LineWrappingStringBuffer(int this._lineLength) : _sb = new StringBuffer(); |
7 | 7 |
8 void add(String s) { | 8 void add(String s) { |
9 if (_lineLength != null && _currentLineLength == _lineLength) { | 9 if (_lineLength != null && _currentLineLength == _lineLength) { |
10 _sb.add('\r\n'); | 10 _sb.add('\r\n'); |
11 _currentLineLength = 0; | 11 _currentLineLength = 0; |
12 } | 12 } |
13 _sb.add(s); | 13 _sb.add(s); |
14 _currentLineLength++; | 14 _currentLineLength++; |
15 } | 15 } |
16 | 16 |
17 String toString() => _sb.toString(); | 17 String toString() => _sb.toString(); |
18 | 18 |
19 int _lineLength; | 19 int _lineLength; |
20 StringBuffer _sb; | 20 StringBuffer _sb; |
21 int _currentLineLength = 0; | 21 int _currentLineLength = 0; |
22 } | 22 } |
23 | 23 |
24 class _CryptoUtils { | 24 abstract class _CryptoUtils { |
25 static String bytesToHex(List<int> bytes) { | 25 static String bytesToHex(List<int> bytes) { |
26 var result = new StringBuffer(); | 26 var result = new StringBuffer(); |
27 for (var part in bytes) { | 27 for (var part in bytes) { |
28 result.add('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); | 28 result.add('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); |
29 } | 29 } |
30 return result.toString(); | 30 return result.toString(); |
31 } | 31 } |
32 | 32 |
33 static String bytesToBase64(List<int> bytes, [int lineLength]) { | 33 static String bytesToBase64(List<int> bytes, [int lineLength]) { |
34 final table = | 34 final table = |
(...skipping 30 matching lines...) Expand all Loading... |
65 var b1 = bytes[i + 1] & 0xff; | 65 var b1 = bytes[i + 1] & 0xff; |
66 result.add(table[b0 >> 2]); | 66 result.add(table[b0 >> 2]); |
67 result.add(table[((b0 << 4) | (b1 >> 4)) & 0x3f]); | 67 result.add(table[((b0 << 4) | (b1 >> 4)) & 0x3f]); |
68 result.add(table[(b1 << 2) & 0x3f]); | 68 result.add(table[(b1 << 2) & 0x3f]); |
69 result.add('='); | 69 result.add('='); |
70 } | 70 } |
71 | 71 |
72 return result.toString(); | 72 return result.toString(); |
73 } | 73 } |
74 } | 74 } |
OLD | NEW |