test/test_helper.rb in rupert-0.0.1 vs test/test_helper.rb in rupert-0.0.2
- old
+ new
@@ -22,9 +22,22 @@
# parsing/generating the IO stream.
def ascii(string)
string.force_encoding(Encoding::ASCII_8BIT)
end
+# Returns a random binary string (8-bit ASCII encoding) of given length
+def random_ascii(size)
+ require 'securerandom'
+ ascii(SecureRandom.random_bytes(size))
+end
+
+# Returns the (strict) base64 representation of given string
+def base64(string)
+ require 'base64'
+
+ Base64.strict_encode64(string)
+end
+
# Pads a string with nulls to fill given length
def pad(string, length)
("%-#{length}.#{length}s" % string).gsub(" ", "\x00")
end