Small doc-syntax fixes

This commit is contained in:
Marcel Stör 2016-01-09 22:46:56 +01:00
parent fe3a6490f6
commit 7d965b2b24
1 changed files with 58 additions and 57 deletions

View File

@ -10,85 +10,69 @@ Compute a cryptographic hash of a Lua string.
`hash = crypto.hash(algo, str)` `hash = crypto.hash(algo, str)`
#### Parameters #### Parameters
- `algo`: The hash algorithm to use, case insensitive string `algo` the hash algorithm to use, case insensitive string
Supported hash algorithms are: Supported hash algorithms are:
- MD2 (not available by default, has to be explicitly enabled in user_config.h)
- MD2 (not available by default, has to be explicitly enabled in `app/include/user_config.h`)
- MD5 - MD5
- SHA1 - SHA1
- SHA256, SHA384, SHA512 (unless disabled in user_config.h) - SHA256, SHA384, SHA512 (unless disabled in `app/include/user_config.h`)
#### Returns #### Returns
A binary string containing the message digest. To obtain the textual version (ASCII hex characters), please use `crypto.toHex()`. A binary string containing the message digest. To obtain the textual version (ASCII hex characters), please use [`crypto.toHex()`](#cryptotohex ).
#### Example #### Example
```lua ```lua
print(crypto.toHex(crypto.hash("sha1","abc"))) print(crypto.toHex(crypto.hash("sha1","abc")))
``` ```
___
## crypto.hmac() ## crypto.hmac()
Compute a HMAC (Hashed Message Authentication Code) signature for a Lua string. Compute a [HMAC](https://en.wikipedia.org/wiki/Hash-based_message_authentication_code) (Hashed Message Authentication Code) signature for a Lua string.
## Syntax #### Syntax
`signature = crypto.hmac(algo, str, key)` `signature = crypto.hmac(algo, str, key)`
#### Parameters #### Parameters
- algo: hash algorithm to use, case insensitive string - `algo` hash algorithm to use, case insensitive string
- str: data to calculate the hash for - `str` data to calculate the hash for
- key: key to use for signing, may be a binary string - `key` key to use for signing, may be a binary string
Supported hash algorithms are: Supported hash algorithms are:
- MD2 (not available by default, has to be explicitly enabled in user_config.h)
- MD2 (not available by default, has to be explicitly enabled in `app/include/user_config.h`)
- MD5 - MD5
- SHA1 - SHA1
- SHA256, SHA384, SHA512 (unless disabled in user_config.h) - SHA256, SHA384, SHA512 (unless disabled in `app/include/user_config.h`)
#### Returns #### Returns
A binary string containing the HMAC signature. Use `crypto.toHex()` to obtain the textual version. A binary string containing the HMAC signature. Use [`crypto.toHex()`](#cryptotohex ) to obtain the textual version.
#### Example #### Example
```lua ```lua
print(crypto.toHex(crypto.hmac("sha1","abc","mysecret"))) print(crypto.toHex(crypto.hmac("sha1","abc","mysecret")))
``` ```
___
## crypto.mask() ## crypto.mask()
Applies an XOR mask to a Lua string. Note that this is not a proper cryptographic mechanism, but some protocols may use it nevertheless. Applies an XOR mask to a Lua string. Note that this is not a proper cryptographic mechanism, but some protocols may use it nevertheless.
#### Syntax #### Syntax
masked = crypto.mask (message, mask) `crypto.mask(message, mask)`
#### Parameters #### Parameters
- message: message to mask - `message` message to mask
- mask = the mask to apply, repeated if shorter than the message - `mask` the mask to apply, repeated if shorter than the message
#### Returns #### Returns
The masked message, as a binary string. Use `crypto.toHex()` to get a textual representation of it. The masked message, as a binary string. Use [`crypto.toHex()`](#cryptotohex) to get a textual representation of it.
#### Example #### Example
```lua ```lua
print(crypto.toHex(crypto.mask("some message to obscure","X0Y7"))) print(crypto.toHex(crypto.mask("some message to obscure","X0Y7")))
``` ```
___
## crypto.toHex()
Provides an ASCII hex representation of a (binary) Lua string. Each byte in the input string is represented as two hex characters in the output.
####Syntax
`hexstr = crypto.toHex(binary)`
####Parameters
- `binary`: input string to get hex representation for
####Returns
An ASCII hex string.
####Example
```lua
print(crypto.toHex(crypto.hash("sha1","abc")))
```
___
## crypto.toBase64() ## crypto.toBase64()
Provides a Base64 representation of a (binary) Lua string. Provides a Base64 representation of a (binary) Lua string.
@ -97,7 +81,7 @@ Provides a Base64 representation of a (binary) Lua string.
`b64 = crypto.toBase64(binary)` `b64 = crypto.toBase64(binary)`
#### Parameters #### Parameters
- `binary`: input string to Base64 encode `binary` input string to Base64 encode
#### Return #### Return
A Base64 encoded string. A Base64 encoded string.
@ -106,4 +90,21 @@ A Base64 encoded string.
```lua ```lua
print(crypto.toBase64(crypto.hash("sha1","abc"))) print(crypto.toBase64(crypto.hash("sha1","abc")))
``` ```
___
## crypto.toHex()
Provides an ASCII hex representation of a (binary) Lua string. Each byte in the input string is represented as two hex characters in the output.
#### Syntax
`hexstr = crypto.toHex(binary)`
#### Parameters
`binary` input string to get hex representation for
#### Returns
An ASCII hex string.
#### Example
```lua
print(crypto.toHex(crypto.hash("sha1","abc")))
```