21
21
22
22
# For much the same reasons as in hash_common.jl, we define a separate, more "Julia friendly" type
23
23
struct CipherType
24
- name:: AbstractString
24
+ name:: String
25
25
context_size:: Cuint
26
26
block_size:: Cuint
27
27
key_size:: Cuint
@@ -49,7 +49,7 @@ function CipherType(nc::NettleCipher)
49
49
end
50
50
51
51
# The global dictionary of hash types we know how to construct
52
- const _cipher_types = Dict {AbstractString ,CipherType} ()
52
+ const _cipher_types = Dict {String ,CipherType} ()
53
53
54
54
# We're going to load in each NettleCipher struct individually, deriving
55
55
# HashAlgorithm types off of the names we find, and storing the output
@@ -83,20 +83,20 @@ function gen_key32_iv16(pw::Vector{UInt8}, salt::Vector{UInt8})
83
83
end
84
84
85
85
function add_padding_PKCS5 (data:: Vector{UInt8} , block_size:: Int )
86
- padlen = block_size - (sizeof (data) % block_size)
87
- return [data; map (i -> UInt8 (padlen), 1 : padlen)]
86
+ padlen = block_size - (sizeof (data) % block_size)
87
+ return [data; map (i -> UInt8 (padlen), 1 : padlen)]
88
88
end
89
89
90
90
function trim_padding_PKCS5 (data:: Vector{UInt8} )
91
- padlen = data[sizeof (data) ]
92
- if all (data[end - padlen+ 1 : end - 1 ] .== data[end ])
93
- return data[1 : sizeof (data) - padlen]
94
- else
95
- throw (ArgumentError (" Invalid PKCS5 padding" ))
96
- end
91
+ padlen = data[end ]
92
+ if all (data[end - padlen+ 1 : end - 1 ] .== data[end ])
93
+ return data[1 : end - padlen]
94
+ else
95
+ throw (ArgumentError (" Invalid PKCS5 padding" ))
96
+ end
97
97
end
98
98
99
- function Encryptor (name:: AbstractString , key)
99
+ function Encryptor (name:: String , key)
100
100
cipher_types = get_cipher_types ()
101
101
name = uppercase (name)
102
102
if ! haskey (cipher_types, name)
@@ -114,7 +114,7 @@ function Encryptor(name::AbstractString, key)
114
114
return Encryptor (cipher_type, state)
115
115
end
116
116
117
- function Decryptor (name:: AbstractString , key)
117
+ function Decryptor (name:: String , key)
118
118
cipher_types = get_cipher_types ()
119
119
name = uppercase (name)
120
120
if ! haskey (cipher_types, name)
@@ -253,11 +253,11 @@ function encrypt(state::Encryptor, data)
253
253
end
254
254
255
255
# The one-shot functions that make this whole thing so easy
256
- decrypt (name:: AbstractString , key, data) = decrypt (Decryptor (name, key), data)
257
- encrypt (name:: AbstractString , key, data) = encrypt (Encryptor (name, key), data)
256
+ decrypt (name:: String , key, data) = decrypt (Decryptor (name, key), data)
257
+ encrypt (name:: String , key, data) = encrypt (Encryptor (name, key), data)
258
258
259
- decrypt (name:: AbstractString , e:: Symbol , iv:: Vector{UInt8} , key, data) = decrypt (Decryptor (name, key), e, iv, data)
260
- encrypt (name:: AbstractString , e:: Symbol , iv:: Vector{UInt8} , key, data) = encrypt (Encryptor (name, key), e, iv, data)
259
+ decrypt (name:: String , e:: Symbol , iv:: Vector{UInt8} , key, data) = decrypt (Decryptor (name, key), e, iv, data)
260
+ encrypt (name:: String , e:: Symbol , iv:: Vector{UInt8} , key, data) = encrypt (Encryptor (name, key), e, iv, data)
261
261
262
262
# Custom show overrides make this package have a little more pizzaz!
263
263
function show (io:: IO , x:: CipherType )
0 commit comments