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

Side by Side Diff: sdk/lib/crypto/crypto_base.dart

Issue 12534011: Add base64 decoder and change existing base64 encoder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address all comments from Florian and Lasse. Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/crypto/crypto_utils.dart » ('j') | sdk/lib/crypto/crypto_utils.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /** 7 /**
8 * Interface for cryptographic hash functions. 8 * Interface for cryptographic hash functions.
9 * 9 *
10 * The [add] method is used to add data to the hash. The [close] method 10 * The [add] method is used to add data to the hash. The [close] method
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 abstract class CryptoUtils { 116 abstract class CryptoUtils {
117 /** 117 /**
118 * Convert a list of bytes (for example a message digest) into a hex 118 * Convert a list of bytes (for example a message digest) into a hex
119 * string. 119 * string.
120 */ 120 */
121 static String bytesToHex(List<int> bytes) { 121 static String bytesToHex(List<int> bytes) {
122 return _CryptoUtils.bytesToHex(bytes); 122 return _CryptoUtils.bytesToHex(bytes);
123 } 123 }
124 124
125 /** 125 /**
126 * Converts a list of bytes (for example a message digest) into a 126 * Converts a list of bytes into a Base 64 encoded string.
127 * base64 encoded string optionally broken up in to lines of 127 *
128 * [lineLength] chars separated by '\r\n'. 128 * The list can be any list of integers in the range 0..255,
129 * for example a message digest.
130 *
131 * If [addLineSeparator] is true, the resulting string will be
132 * broken into lines of 76 characters, separated by "\r\n".
133 *
134 * If [urlSafe] is true, the result is URL and filename safe.
135 *
136 * If [usePadding] is false, No extra padding characters ('=') are
137 * appended to the output.
138 *
139 * Based on RFC 4648 http://tools.ietf.org/html/rfc4648
floitsch 2013/03/25 17:45:37 nit: I think Markdown has a way to specify URLs. N
mdakin1 2013/03/26 09:52:17 Done.
140 *
129 */ 141 */
130 static String bytesToBase64(List<int> bytes, [int lineLength]) { 142 static String bytesToBase64(List<int> bytes,
131 return _CryptoUtils.bytesToBase64(bytes, lineLength); 143 {bool urlSafe : false,
144 bool addLineSeparator : false}) {
145 return _CryptoUtils.bytesToBase64(bytes,
146 urlSafe,
147 addLineSeparator);
132 } 148 }
149
150
151 /**
152 * Converts a Base 64 encoded String into list of bytes.
153 *
154 * Decoder ignores "\r\n" sequences from input. By default it also ignores
155 * all illegal characters unless [ignoreErrors] is false.
156 *
157 * Accepts both URL safe and unsafe Base 64 encoded strings.
158 *
159 * Based on RFC 4648 http://tools.ietf.org/html/rfc4648
floitsch 2013/03/25 17:45:37 ditto.
mdakin1 2013/03/26 09:52:17 Done.
160 */
161 static List<int> base64StringToBytes(String input, {bool ignoreErrors : true}) {
162 return _CryptoUtils.base64StringToBytes(input, ignoreErrors);
163 }
164
133 } 165 }
134 166
135 /** 167 /**
136 * HashExceptions are thrown on invalid use of a Hash 168 * HashExceptions are thrown on invalid use of a Hash
137 * object. 169 * object.
138 */ 170 */
139 class HashException { 171 class HashException {
140 HashException(String this.message); 172 HashException(String this.message);
141 toString() => "HashException: $message"; 173 toString() => "HashException: $message";
142 String message; 174 String message;
143 } 175 }
144 176
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/crypto/crypto_utils.dart » ('j') | sdk/lib/crypto/crypto_utils.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698