Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 02f5555de42f
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 44d0345b5097
Choose a head ref
  • 2 commits
  • 48 files changed
  • 1 contributor

Commits on Dec 18, 2016

  1. Use Bytes.empty throughout the codebase

    Sija authored and Ary Borenszweig committed Dec 18, 2016
    Copy the full SHA
    97b4f35 View commit details
  2. Replace Slice(UInt8) with Bytes throughout the codebase

    Sija authored and Ary Borenszweig committed Dec 18, 2016
    Copy the full SHA
    44d0345 View commit details
Showing with 152 additions and 152 deletions.
  1. +1 −1 spec/std/base64_spec.cr
  2. +2 −2 spec/std/crypto/bcrypt_spec.cr
  3. +4 −4 spec/std/http/server/server_spec.cr
  4. +10 −10 spec/std/http/web_socket_spec.cr
  5. +4 −4 spec/std/io/buffered_spec.cr
  6. +1 −1 spec/std/io/delimited_spec.cr
  7. +2 −2 spec/std/io/hexdump_spec.cr
  8. +6 −6 spec/std/io/io_spec.cr
  9. +1 −1 spec/std/secure_random_spec.cr
  10. +3 −3 spec/std/slice_spec.cr
  11. +2 −2 spec/std/string_pool_spec.cr
  12. +2 −2 spec/std/zlib/inflate_spec.cr
  13. +1 −1 src/base64.cr
  14. +2 −2 src/bit_array.cr
  15. +5 −5 src/crypto/bcrypt.cr
  16. +2 −2 src/crypto/bcrypt/base64.cr
  17. +3 −3 src/crypto/md5.cr
  18. +1 −1 src/debug/elf.cr
  19. +4 −4 src/digest/sha1.cr
  20. +5 −5 src/http/content.cr
  21. +5 −5 src/http/server/response.cr
  22. +1 −1 src/http/web_socket.cr
  23. +7 −7 src/http/web_socket/protocol.cr
  24. +16 −16 src/io.cr
  25. +2 −2 src/io/argf.cr
  26. +6 −6 src/io/buffered.cr
  27. +3 −3 src/io/delimited.cr
  28. +6 −6 src/io/encoding.cr
  29. +3 −3 src/io/file_descriptor.cr
  30. +2 −2 src/io/hexdump.cr
  31. +3 −3 src/io/memory.cr
  32. +2 −2 src/io/multi_writer.cr
  33. +2 −2 src/io/sized.cr
  34. +2 −2 src/openssl/cipher.cr
  35. +2 −2 src/openssl/hmac.cr
  36. +2 −2 src/openssl/pkcs5.cr
  37. +3 −3 src/openssl/ssl/context.cr
  38. +2 −2 src/openssl/ssl/socket.cr
  39. +1 −1 src/openssl/x509/extension.cr
  40. +1 −1 src/openssl/x509/name.cr
  41. +5 −5 src/secure_random.cr
  42. +4 −4 src/socket/udp_socket.cr
  43. +3 −3 src/string.cr
  44. +2 −2 src/string/builder.cr
  45. +1 −1 src/string/formatter.cr
  46. +1 −1 src/string_pool.cr
  47. +2 −2 src/zlib/deflate.cr
  48. +2 −2 src/zlib/inflate.cr
2 changes: 1 addition & 1 deletion spec/std/base64_spec.cr
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ describe "Base64" do
end

it "encodes byte slice" do
slice = Slice(UInt8).new(5) { 1_u8 }
slice = Bytes.new(5) { 1_u8 }
Base64.encode(slice).should eq("AQEBAQE=\n")
Base64.strict_encode(slice).should eq("AQEBAQE=")
end
4 changes: 2 additions & 2 deletions spec/std/crypto/bcrypt_spec.cr
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ require "spec"
require "crypto/bcrypt"

describe "Crypto::Bcrypt" do
latin1_pound_sign = String.new(Slice(UInt8).new(1, 0xa3_u8))
utf8_pound_sign = String.new(Slice(UInt8).new(2) { |i| i == 0 ? 0xc2_u8 : 0xa3_u8 })
latin1_pound_sign = String.new(Bytes.new(1, 0xa3_u8))
utf8_pound_sign = String.new(Bytes.new(2) { |i| i == 0 ? 0xc2_u8 : 0xa3_u8 })
bit8_unicode_pound_sign = "\u00A3"

vectors = [
8 changes: 4 additions & 4 deletions spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@ private class RaiseErrno

include IO

def read(slice : Slice(UInt8))
def read(slice : Bytes)
Errno.value = @value
raise Errno.new "..."
end

def write(slice : Slice(UInt8)) : Nil
def write(slice : Bytes) : Nil
raise "not implemented"
end
end
@@ -25,13 +25,13 @@ private class ReverseResponseOutput
def initialize(@output : IO)
end

def write(slice : Slice(UInt8))
def write(slice : Bytes)
slice.reverse_each do |byte|
@output.write_byte(byte)
end
end

def read(slice : Slice(UInt8))
def read(slice : Bytes)
raise "Not implemented"
end

20 changes: 10 additions & 10 deletions spec/std/http/web_socket_spec.cr
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(64)
buffer = Bytes.new(64)
result = ws.receive(buffer)
assert_text_packet result, 5, final: true
String.new(buffer[0, result.size]).should eq("Hello")
@@ -42,7 +42,7 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(3)
buffer = Bytes.new(3)

2.times do
result = ws.receive(buffer)
@@ -61,7 +61,7 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(3)
buffer = Bytes.new(3)

2.times do
result = ws.receive(buffer)
@@ -81,7 +81,7 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(10)
buffer = Bytes.new(10)

2.times do
result = ws.receive(buffer)
@@ -99,7 +99,7 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(64)
buffer = Bytes.new(64)
result = ws.receive(buffer)
assert_ping_packet result, 5, final: true
String.new(buffer[0, result.size]).should eq("Hello")
@@ -112,7 +112,7 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(64)
buffer = Bytes.new(64)

result = ws.receive(buffer)
assert_text_packet result, 3, final: false
@@ -132,23 +132,23 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(2048)
buffer = Bytes.new(2048)

result = ws.receive(buffer)
assert_text_packet result, 1023, final: true
String.new(buffer[0, 1023]).should eq("x" * 1023)
end

it "read very long packet" do
data = Slice(UInt8).new(10 + 0x010000)
data = Bytes.new(10 + 0x010000)

header = Bytes[0x82, 127_u8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0]
data.copy_from(header)

io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(0x010000)
buffer = Bytes.new(0x010000)

result = ws.receive(buffer)
assert_binary_packet result, 0x010000, final: true
@@ -159,7 +159,7 @@ describe HTTP::WebSocket do
io = IO::Memory.new(data)
ws = HTTP::WebSocket::Protocol.new(io)

buffer = Slice(UInt8).new(64)
buffer = Bytes.new(64)
result = ws.receive(buffer)
assert_close_packet result, 0, final: true
end
8 changes: 4 additions & 4 deletions spec/std/io/buffered_spec.cr
Original file line number Diff line number Diff line change
@@ -19,12 +19,12 @@ private class BufferedWrapper
io
end

private def unbuffered_read(slice : Slice(UInt8))
private def unbuffered_read(slice : Bytes)
@called_unbuffered_read = true
@io.read(slice)
end

private def unbuffered_write(slice : Slice(UInt8))
private def unbuffered_write(slice : Bytes)
@io.write(slice)
end

@@ -189,7 +189,7 @@ describe "IO::Buffered" do
end
io = BufferedWrapper.new(IO::Memory.new(s))

slice = Slice(UInt8).new(9000)
slice = Bytes.new(9000)
count = io.read(slice)
count.should eq(9000)

@@ -283,7 +283,7 @@ describe "IO::Buffered" do
it "shouldn't call unbuffered read if reading to an empty slice" do
str = IO::Memory.new("foo")
io = BufferedWrapper.new(str)
io.read(Slice(UInt8).new(0))
io.read(Bytes.new(0))
io.called_unbuffered_read.should be_false
end

2 changes: 1 addition & 1 deletion spec/std/io/delimited_spec.cr
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ require "spec"
private class PartialReaderIO
include IO

@slice : Slice(UInt8)
@slice : Bytes

def initialize(data : String)
@slice = data.to_slice
4 changes: 2 additions & 2 deletions spec/std/io/hexdump_spec.cr
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ describe IO::Hexdump do
io = IO::Memory.new(ascii_table.bytesize)
r = IO::Hexdump.new(r, output: io, read: true)

slice = Slice(UInt8).new(101) { |i| i.to_u8 + 32 }
slice = Bytes.new(101) { |i| i.to_u8 + 32 }
w.write(slice)

buf = uninitialized UInt8[101]
@@ -45,7 +45,7 @@ describe IO::Hexdump do
io = IO::Memory.new(ascii_table.bytesize)
w = IO::Hexdump.new(w, output: io, write: true)

slice = Slice(UInt8).new(96) { |i| i.to_u8 + 32 }
slice = Bytes.new(96) { |i| i.to_u8 + 32 }
w.write(slice)

buf = uninitialized UInt8[96]
12 changes: 6 additions & 6 deletions spec/std/io/io_spec.cr
Original file line number Diff line number Diff line change
@@ -27,13 +27,13 @@ private class SimpleIOMemory
io
end

def self.new(bytes : Slice(UInt8), max_read = nil)
def self.new(bytes : Bytes, max_read = nil)
io = new(bytes.size, max_read: max_read)
io.write(bytes)
io
end

def read(slice : Slice(UInt8))
def read(slice : Bytes)
count = slice.size
count = Math.min(count, @bytesize - @pos)
if max_read = @max_read
@@ -44,7 +44,7 @@ private class SimpleIOMemory
count
end

def write(slice : Slice(UInt8))
def write(slice : Bytes)
count = slice.size
new_bytesize = bytesize + count
if new_bytesize > @capacity
@@ -98,7 +98,7 @@ describe IO do
it "doesn't block on first read. blocks on 2nd read" do
IO.pipe do |read, write|
write.puts "hello"
slice = Slice(UInt8).new 1024
slice = Bytes.new 1024

read.read_timeout = 1
read.read(slice).should eq(6)
@@ -343,7 +343,7 @@ describe IO do

it "does read_fully" do
str = SimpleIOMemory.new("hello")
slice = Slice(UInt8).new(4)
slice = Bytes.new(4)
str.read_fully(slice).should eq(4)
String.new(slice).should eq("hell")

@@ -354,7 +354,7 @@ describe IO do

it "does read_fully?" do
str = SimpleIOMemory.new("hello")
slice = Slice(UInt8).new(4)
slice = Bytes.new(4)
str.read_fully?(slice).should eq(4)
String.new(slice).should eq("hell")

2 changes: 1 addition & 1 deletion spec/std/secure_random_spec.cr
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ describe SecureRandom do

it "fully fills a large buffer" do
bytes = SecureRandom.random_bytes(10000)
bytes[9990, 10].should_not eq(Slice(UInt8).new(10))
bytes[9990, 10].should_not eq(Bytes.new(10))
end
end

6 changes: 3 additions & 3 deletions spec/std/slice_spec.cr
Original file line number Diff line number Diff line change
@@ -230,7 +230,7 @@ describe "Slice" do
end

it "does hexstring" do
slice = Slice(UInt8).new(4) { |i| i.to_u8 + 1 }
slice = Bytes.new(4) { |i| i.to_u8 + 1 }
slice.hexstring.should eq("01020304")
end

@@ -244,7 +244,7 @@ describe "Slice" do
00000050 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.
EOF

slice = Slice(UInt8).new(96) { |i| i.to_u8 + 32 }
slice = Bytes.new(96) { |i| i.to_u8 + 32 }
slice.hexdump.should eq(ascii_table)

ascii_table_plus = <<-EOF
@@ -257,7 +257,7 @@ describe "Slice" do
00000060 80 81 82 83 84 .....
EOF

plus = Slice(UInt8).new(101) { |i| i.to_u8 + 32 }
plus = Bytes.new(101) { |i| i.to_u8 + 32 }
plus.hexdump.should eq(ascii_table_plus)
end

4 changes: 2 additions & 2 deletions spec/std/string_pool_spec.cr
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ describe StringPool do

it "gets slice" do
pool = StringPool.new
slice = Slice(UInt8).new(3, 'a'.ord.to_u8)
slice = Bytes.new(3, 'a'.ord.to_u8)

s1 = pool.get(slice)
s2 = pool.get(slice)
@@ -47,7 +47,7 @@ describe StringPool do

it "gets pointer with size" do
pool = StringPool.new
slice = Slice(UInt8).new(3, 'a'.ord.to_u8)
slice = Bytes.new(3, 'a'.ord.to_u8)

s1 = pool.get(slice.pointer(slice.size), slice.size)
s2 = pool.get(slice.pointer(slice.size), slice.size)
4 changes: 2 additions & 2 deletions spec/std/zlib/inflate_spec.cr
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ module Zlib
end

str.should eq("this is a test string !!!!\n")
inflate.read(Slice(UInt8).new(10)).should eq(0)
inflate.read(Bytes.new(10)).should eq(0)
end

it "can be closed without sync" do
@@ -62,7 +62,7 @@ module Zlib
end
io.rewind
inflate = Inflate.new(io)
slice = Slice(UInt8).new(0)
slice = Bytes.new(0)
inflate.read(slice).should eq(0)
end
end
2 changes: 1 addition & 1 deletion src/base64.cr
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ module Base64
strict_encode_to_io_internal(data, io, CHARS_SAFE, pad: true)
end

# Returns the Base64-decoded version of `data` as a *Slice(UInt8)*.
# Returns the Base64-decoded version of `data` as a *Bytes*.
# This will decode either the normal or urlsafe alphabets.
def decode(data) : Bytes
slice = data.to_slice
4 changes: 2 additions & 2 deletions src/bit_array.cr
Original file line number Diff line number Diff line change
@@ -94,10 +94,10 @@ struct BitArray
to_s(io)
end

# Returns a Slice(UInt8) able to read and write bytes from a buffer.
# Returns a `Bytes` able to read and write bytes from a buffer.
# The slice will be long enough to hold all the bits groups in bytes despite the `UInt32` internal representation.
# It's useful for reading and writing a bit array from a byte buffer directly.
def to_slice : Slice(UInt8)
def to_slice : Bytes
Slice.new(@bits.as(Pointer(UInt8)), (@size / 8.0).ceil.to_i)
end

10 changes: 5 additions & 5 deletions src/crypto/bcrypt.cr
Original file line number Diff line number Diff line change
@@ -54,17 +54,17 @@ class Crypto::Bcrypt
new(passwordb, saltb, cost)
end

getter password : Slice(UInt8)
getter salt : Slice(UInt8)
getter password : Bytes
getter salt : Bytes
getter cost : Int32

def initialize(@password : Slice(UInt8), @salt : Slice(UInt8), @cost = DEFAULT_COST)
def initialize(@password : Bytes, @salt : Bytes, @cost = DEFAULT_COST)
raise Error.new("Invalid cost") unless COST_RANGE.includes?(cost)
raise Error.new("Invalid salt size") unless salt.size == SALT_SIZE
raise Error.new("Invalid password size") unless PASSWORD_RANGE.includes?(password.size)
end

@digest : Slice(UInt8)?
@digest : Bytes?

def digest
@digest ||= hash_password
@@ -104,7 +104,7 @@ class Crypto::Bcrypt
end
end

ret = Slice(UInt8).new(size * 4)
ret = Bytes.new(size * 4)
j = -1

size.times do |i|
4 changes: 2 additions & 2 deletions src/crypto/bcrypt/base64.cr
Original file line number Diff line number Diff line change
@@ -57,11 +57,11 @@ module Crypto::Bcrypt::Base64
end
end

def self.decode(string, maxolen) : Slice(UInt8)
def self.decode(string, maxolen) : Bytes
off, slen, olen = 0, string.size, 0

i = -1
str = Slice(UInt8).new(maxolen)
str = Bytes.new(maxolen)

while off < slen - 1 && olen < maxolen
c1, c2 = char64(string[off]), char64(string[off + 1])
Loading