aboutsummaryrefslogtreecommitdiff
path: root/okio/src/commonMain/kotlin/okio/ByteString.kt
diff options
context:
space:
mode:
Diffstat (limited to 'okio/src/commonMain/kotlin/okio/ByteString.kt')
-rw-r--r--okio/src/commonMain/kotlin/okio/ByteString.kt58
1 files changed, 38 insertions, 20 deletions
diff --git a/okio/src/commonMain/kotlin/okio/ByteString.kt b/okio/src/commonMain/kotlin/okio/ByteString.kt
index 7eb34c6a..3f4fb82f 100644
--- a/okio/src/commonMain/kotlin/okio/ByteString.kt
+++ b/okio/src/commonMain/kotlin/okio/ByteString.kt
@@ -42,7 +42,7 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
internal var hashCode: Int
internal var utf8: String?
- /** Constructs a new `String` by decoding the bytes as `UTF-8`. */
+ /** Constructs a new `String` by decoding the bytes as `UTF-8`. */
fun utf8(): String
/**
@@ -54,29 +54,38 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
/** Returns this byte string encoded as [URL-safe Base64](http://www.ietf.org/rfc/rfc4648.txt). */
fun base64Url(): String
- /** Returns this byte string encoded in hexadecimal. */
+ /** Returns this byte string encoded in hexadecimal. */
fun hex(): String
- /** Returns the 128-bit MD5 hash of this byte string. */
+ /**
+ * Returns the 128-bit MD5 hash of this byte string.
+ *
+ * MD5 has been vulnerable to collisions since 2004. It should not be used in new code.
+ */
fun md5(): ByteString
- /** Returns the 160-bit SHA-1 hash of this byte string. */
+ /**
+ * Returns the 160-bit SHA-1 hash of this byte string.
+ *
+ * SHA-1 has been vulnerable to collisions since 2017. It should not be used in new code.
+ */
fun sha1(): ByteString
- /** Returns the 256-bit SHA-256 hash of this byte string. */
+ /** Returns the 256-bit SHA-256 hash of this byte string. */
fun sha256(): ByteString
- /** Returns the 512-bit SHA-512 hash of this byte string. */
+ /** Returns the 512-bit SHA-512 hash of this byte string. */
fun sha512(): ByteString
- /** Returns the 160-bit SHA-1 HMAC of this byte string. */
+ /** Returns the 160-bit SHA-1 HMAC of this byte string. */
fun hmacSha1(key: ByteString): ByteString
- /** Returns the 256-bit SHA-256 HMAC of this byte string. */
+ /** Returns the 256-bit SHA-256 HMAC of this byte string. */
fun hmacSha256(key: ByteString): ByteString
- /** Returns the 512-bit SHA-512 HMAC of this byte string. */
+ /** Returns the 512-bit SHA-512 HMAC of this byte string. */
fun hmacSha512(key: ByteString): ByteString
+
/**
* Returns a byte string equal to this byte string, but with the bytes 'A' through 'Z' replaced
* with the corresponding byte in 'a' through 'z'. Returns this byte string if it contains no
@@ -89,7 +98,7 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
* `beginIndex` and ends at the specified `endIndex`. Returns this byte string if `beginIndex` is
* 0 and `endIndex` is the length of this byte string.
*/
- fun substring(beginIndex: Int = 0, endIndex: Int = size): ByteString
+ fun substring(beginIndex: Int = 0, endIndex: Int = DEFAULT__ByteString_size): ByteString
/**
* Returns a byte string equal to this byte string, but with the bytes 'a' through 'z' replaced
@@ -98,16 +107,17 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
*/
fun toAsciiUppercase(): ByteString
- /** Returns the byte at `pos`. */
+ /** Returns the byte at `pos`. */
internal fun internalGet(pos: Int): Byte
- /** Returns the byte at `index`. */
+ /** Returns the byte at `index`. */
@JvmName("getByte")
operator fun get(index: Int): Byte
/** Returns the number of bytes in this ByteString. */
val size: Int
- @JvmName("size") get
+ @JvmName("size")
+ get
// Hack to work around Kotlin's limitation for using JvmName on open/override vals/funs
internal fun getSize(): Int
@@ -115,7 +125,7 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
/** Returns a byte array containing a copy of the bytes in this `ByteString`. */
fun toByteArray(): ByteArray
- /** Writes the contents of this byte string to `buffer`. */
+ /** Writes the contents of this byte string to `buffer`. */
internal fun write(buffer: Buffer, offset: Int, byteCount: Int)
/** Returns the bytes of this string without a defensive copy. Do not mutate! */
@@ -133,6 +143,14 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
*/
fun rangeEquals(offset: Int, other: ByteArray, otherOffset: Int, byteCount: Int): Boolean
+ /**
+ * Copies bytes of this in `[offset..offset+byteCount]` to other in
+ * `[targetOffset..targetOffset+byteCount]`.
+ *
+ * @throws IndexOutOfBoundsException if either range is out of bounds.
+ */
+ fun copyInto(offset: Int = 0, target: ByteArray, targetOffset: Int = 0, byteCount: Int)
+
fun startsWith(prefix: ByteString): Boolean
fun startsWith(prefix: ByteArray): Boolean
@@ -147,9 +165,9 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
@JvmOverloads
fun indexOf(other: ByteArray, fromIndex: Int = 0): Int
- fun lastIndexOf(other: ByteString, fromIndex: Int = size): Int
+ fun lastIndexOf(other: ByteString, fromIndex: Int = DEFAULT__ByteString_size): Int
- fun lastIndexOf(other: ByteArray, fromIndex: Int = size): Int
+ fun lastIndexOf(other: ByteArray, fromIndex: Int = DEFAULT__ByteString_size): Int
override fun equals(other: Any?): Boolean
@@ -164,7 +182,7 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
override fun toString(): String
companion object {
- /** A singleton empty `ByteString`. */
+ /** A singleton empty `ByteString`. */
@JvmField
val EMPTY: ByteString
@@ -177,9 +195,9 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
* starting at `offset`.
*/
@JvmStatic
- fun ByteArray.toByteString(offset: Int = 0, byteCount: Int = size): ByteString
+ fun ByteArray.toByteString(offset: Int = 0, byteCount: Int = DEFAULT__ByteString_size): ByteString
- /** Returns a new byte string containing the `UTF-8` bytes of this [String]. */
+ /** Returns a new byte string containing the `UTF-8` bytes of this [String]. */
@JvmStatic
fun String.encodeUtf8(): ByteString
@@ -190,7 +208,7 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
@JvmStatic
fun String.decodeBase64(): ByteString?
- /** Decodes the hex-encoded bytes and returns their value a byte string. */
+ /** Decodes the hex-encoded bytes and returns their value a byte string. */
@JvmStatic
fun String.decodeHex(): ByteString
}