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

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 comments. 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, Extra padding characters ('=') are not
floitsch 2013/03/22 17:22:05 If [usePadding] is false, no extra padding charact
mdakin1 2013/03/25 17:05:02 Done.
137 * appended to output.
138 *
139 * Based on RFC 4648 http://tools.ietf.org/html/rfc4648
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 bool usePadding : true}) {
146 return _CryptoUtils.bytesToBase64(bytes,
147 urlSafe,
148 addLineSeparator,
149 usePadding);
132 } 150 }
151
152
153 /**
154 * Converts a Base 64 encoded String into list of bytes.
155 *
156 * Decoder ignores "\r\n" sequences from input. By default it also ignores
157 * all illegal characters unless [ignoreErrors] is false.
158 *
159 * Accepts both URL safe and unsafe Base 64 encoded strings.
160 *
161 * Returns an empty list if [input] is null.
floitsch 2013/03/22 17:22:05 Why not throw a null-pointer exception? (in which
mdakin1 2013/03/25 17:05:02 Done, no mention of null anymore.
162 *
163 * Based on RFC 4648 http://tools.ietf.org/html/rfc4648
164 */
165 static List<int> base64StringToBytes(String input, {bool ignoreErrors : true}) {
166 return _CryptoUtils.base64StringToBytes(input, ignoreErrors);
167 }
168
133 } 169 }
134 170
135 /** 171 /**
136 * HashExceptions are thrown on invalid use of a Hash 172 * HashExceptions are thrown on invalid use of a Hash
137 * object. 173 * object.
138 */ 174 */
139 class HashException { 175 class HashException {
140 HashException(String this.message); 176 HashException(String this.message);
141 toString() => "HashException: $message"; 177 toString() => "HashException: $message";
142 String message; 178 String message;
143 } 179 }
144 180
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