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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/crypto/crypto_utils.dart » ('j') | sdk/lib/crypto/crypto_utils.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/crypto/crypto_base.dart
diff --git a/sdk/lib/crypto/crypto_base.dart b/sdk/lib/crypto/crypto_base.dart
index d1666b51ed9a7bafb0a5537301fb92a67b2577d5..4737e1db6407432804686893f0c665d8b25b907f 100644
--- a/sdk/lib/crypto/crypto_base.dart
+++ b/sdk/lib/crypto/crypto_base.dart
@@ -123,13 +123,49 @@ abstract class CryptoUtils {
}
/**
- * Converts a list of bytes (for example a message digest) into a
- * base64 encoded string optionally broken up in to lines of
- * [lineLength] chars separated by '\r\n'.
+ * Converts a list of bytes into a Base 64 encoded string.
+ *
+ * The list can be any list of integers in the range 0..255,
+ * for example a message digest.
+ *
+ * If [addLineSeparator] is true, the resulting string will be
+ * broken into lines of 76 characters, separated by "\r\n".
+ *
+ * If [urlSafe] is true, the result is URL and filename safe.
+ *
+ * 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.
+ * appended to output.
+ *
+ * Based on RFC 4648 http://tools.ietf.org/html/rfc4648
+ *
+ */
+ static String bytesToBase64(List<int> bytes,
+ {bool urlSafe : false,
+ bool addLineSeparator : false,
+ bool usePadding : true}) {
+ return _CryptoUtils.bytesToBase64(bytes,
+ urlSafe,
+ addLineSeparator,
+ usePadding);
+ }
+
+
+ /**
+ * Converts a Base 64 encoded String into list of bytes.
+ *
+ * Decoder ignores "\r\n" sequences from input. By default it also ignores
+ * all illegal characters unless [ignoreErrors] is false.
+ *
+ * Accepts both URL safe and unsafe Base 64 encoded strings.
+ *
+ * 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.
+ *
+ * Based on RFC 4648 http://tools.ietf.org/html/rfc4648
*/
- static String bytesToBase64(List<int> bytes, [int lineLength]) {
- return _CryptoUtils.bytesToBase64(bytes, lineLength);
+ static List<int> base64StringToBytes(String input, {bool ignoreErrors : true}) {
+ return _CryptoUtils.base64StringToBytes(input, ignoreErrors);
}
+
}
/**
« 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