#crypto/cipher
Xu 0.16.0 API
import: #crypto/cipher
counts: 18 functions, 3 methods, 2 types, 0 constants, 0 method sets
AES-CBC/CTR/GCM bound to crypto.aes.Cipher.
pad_pkcs7
pub fn pad_pkcs7(src &string, block_size int) string
Purpose
Pad pkcs7. Throws on failure; handle the error or propagate it to the caller.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
block_size int- block_size (int)
Returns
string — result string
unpad_pkcs7_block
pub fn unpad_pkcs7_block(src &string, block_size int) string
Purpose
Unpad pkcs7 block. Throws on failure; handle the error or propagate it to the caller.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
block_size int- block_size (int)
Returns
string — result string
unpad_pkcs7
pub fn unpad_pkcs7(src &string) string
Purpose
Unpad pkcs7. Throws on failure; handle the error or propagate it to the caller.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
encrypt_cbc
pub fn encrypt_cbc(c &aes.Cipher, iv &string, src &string) string
Purpose
Encrypt cbc. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
decrypt_cbc
pub fn decrypt_cbc(c &aes.Cipher, iv &string, src &string) string
Purpose
Decrypt cbc. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
encrypt_cbc_pkcs7
pub fn encrypt_cbc_pkcs7(c &aes.Cipher, iv &string, src &string) string
Purpose
Encrypt cbc pkcs7. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
decrypt_cbc_pkcs7
pub fn decrypt_cbc_pkcs7(c &aes.Cipher, iv &string, src &string) string
Purpose
Decrypt cbc pkcs7. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
encrypt_ctr
pub fn encrypt_ctr(c &aes.Cipher, iv &string, src &string) string
Purpose
Encrypt ctr.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
decrypt_ctr
pub fn decrypt_ctr(c &aes.Cipher, iv &string, src &string) string
Purpose
Decrypt ctr.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
struct Ctr
Purpose
Ctr is a resumable CTR keystream ( cipher.NewCTR): successive xor_key_stream calls continue mid-block where the previous one stopped.
Public fields
This type has no public fields.
new_ctr
pub fn new_ctr(c aes.Cipher, iv &string) Ctr
Purpose
Construct ctr. Throws on failure; handle the error or propagate it to the caller.
Parameters
c aes.Cipher- byte or character code (aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
Returns
Ctr — a value of this type
($&Ctr) xor_key_stream
pub fn (s $&Ctr) xor_key_stream(src &string) string
Purpose
Operation on $&Ctr: xor key stream. Throws on failure; handle the error or propagate it to the caller.
Parameters
s $&Ctr- The
Ctr instance used by this call (exclusive borrow).
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
encrypt_ofb
pub fn encrypt_ofb(c &aes.Cipher, iv &string, src &string) string
Purpose
Encrypt ofb. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
decrypt_ofb
pub fn decrypt_ofb(c &aes.Cipher, iv &string, src &string) string
Purpose
Decrypt ofb. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
encrypt_cfb
pub fn encrypt_cfb(c &aes.Cipher, iv &string, src &string) string
Purpose
Encrypt cfb. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
decrypt_cfb
pub fn decrypt_cfb(c &aes.Cipher, iv &string, src &string) string
Purpose
Decrypt cfb. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
iv &string- int payload or initialization vector (read-only borrow; caller keeps the original; type &string)
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
struct GcmKey
Purpose
GcmKey context or state structure.
Public fields
This type has no public fields.
empty_gcm
pub fn empty_gcm() GcmKey
Purpose
Empty gcm.
Parameters
No arguments are required.
Returns
GcmKey — a value of this type
new_gcm
pub fn new_gcm(c aes.Cipher) GcmKey
Purpose
Construct gcm. Throws on failure; handle the error or propagate it to the caller.
Parameters
c aes.Cipher- byte or character code (aes.Cipher)
Returns
GcmKey — a value of this type
(&GcmKey) seal
pub fn (g &GcmKey) seal(nonce &string, plaintext &string, aad &string) string
Purpose
Execute seal on &GcmKey. Throws on failure; handle the error or propagate it to the caller.
Parameters
g &GcmKey- The
GcmKey instance used by this call (borrow).
nonce &string- nonce (read-only borrow; caller keeps the original; type &string)
plaintext &string- plaintext (read-only borrow; caller keeps the original; type &string)
aad &string- aad (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
(&GcmKey) open
pub fn (g &GcmKey) open(nonce &string, sealed &string, aad &string) string
Purpose
Operation on &GcmKey: open resource or establish connection. Throws on failure; handle the error or propagate it to the caller.
Parameters
g &GcmKey- The
GcmKey instance used by this call (borrow).
nonce &string- nonce (read-only borrow; caller keeps the original; type &string)
sealed &string- sealed (read-only borrow; caller keeps the original; type &string)
aad &string- aad (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
seal_gcm
pub fn seal_gcm(c &aes.Cipher, nonce &string, plaintext &string, aad &string) string
Purpose
Seal gcm. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
nonce &string- nonce (read-only borrow; caller keeps the original; type &string)
plaintext &string- plaintext (read-only borrow; caller keeps the original; type &string)
aad &string- aad (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
open_gcm
pub fn open_gcm(c &aes.Cipher, nonce &string, sealed &string, aad &string) string
Purpose
Open gcm. Throws on failure; handle the error or propagate it to the caller.
Parameters
c &aes.Cipher- byte or character code (read-only borrow; caller keeps the original; type &aes.Cipher)
nonce &string- nonce (read-only borrow; caller keeps the original; type &string)
sealed &string- sealed (read-only borrow; caller keeps the original; type &string)
aad &string- aad (read-only borrow; caller keeps the original; type &string)
Returns
string — result string