MBMLEncodingFunctions Class Reference

Inherits from NSObject
Declared in MBMLEncodingFunctions.h

Overview

This class implements a set of MBML functions to be used for encoding strings and data into other representations, such as MD5, base-64, etc.

<Function ... /> declarations in the MBDataEnvironmentModule.xml file.

For more information on MBML functions, see the MBMLFunction class.

MD5 encoding

+ MD5FromString:

Computes an MD5 hash from an input string.

+ (id)MD5FromString:(NSString *)string

Parameters

string

The function’s input string.

Return Value

An MD5 hash computed from the input string. The hash is returned as a hexadecimal string.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield the input string.

Expression usage

The expression:

^MD5FromString(12 Galaxies)

would return the string 51eae4327df7f0617eaaf305832fe219, a hexadecimal representation of the MD5 hash of the string “12 Galaxies”.

Note: This function is also exposed to the Mockingbird environment with the alias ^MD5().

Declared In

MBMLEncodingFunctions.h

+ MD5FromData:

Computes an MD5 hash from an NSData instance.

+ (id)MD5FromData:(NSData *)data

Parameters

data

The function’s input data.

Return Value

An MD5 hash computed from the input data. The hash is returned as a hexadecimal string.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield an NSData instance.

Expression usage

The expression:

^MD5FromData($myData)

would return a hexadecimal string representation of the MD5 hash of the bytes contained in the NSData instance yielded by the MBML expression “$myData

Declared In

MBMLEncodingFunctions.h

SHA-1 encoding

+ SHA1FromString:

Computes an SHA-1 hash from an input string.

+ (id)SHA1FromString:(NSString *)string

Parameters

string

The function’s input string.

Return Value

An SHA-1 hash computed from the input string.The hash is returned as a hexadecimal string.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield the input string.

Expression usage

The expression:

^SHA1FromString(12 Galaxies)

would return the string b9f4599289911696e76d1e401a449dbf3dd97b72, a hexadecimal representation of the SHA1 hash of the string “12 Galaxies”.

Note: This function is also exposed to the Mockingbird environment with the alias ^SHA1().

Declared In

MBMLEncodingFunctions.h

+ SHA1FromData:

Computes an SHA-1 hash from an NSData instance.

+ (id)SHA1FromData:(NSData *)data

Parameters

data

The function’s input data.

Return Value

An SHA-1 hash computed from the input data.The hash is returned as a hexadecimal string.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield an NSData instance.

Expression usage

The expression:

^SHA1FromData($myData)

would return a hexadecimal string representation of the SHA-1 hash of the bytes contained in the NSData instance yielded by the MBML expression “$myData

Declared In

MBMLEncodingFunctions.h

Base-64 encoding & decoding

+ base64FromData:

Computes a Base-64 representation of a given NSData instance, and returns the resulting string.

+ (id)base64FromData:(NSData *)data

Parameters

data

The function’s input data.

Return Value

The base-64 representation of the input data.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield an NSData instance.

Expression usage

The expression:

^base64FromData($myData)

would return a string that contains the Base-64 encoding of the bytes within the NSData instance yielded by the MBML expression “$myData”.

Declared In

MBMLEncodingFunctions.h

+ dataFromBase64:

Decodes a Base-64 string representation of data, and returns the resulting NSData instance.

+ (id)dataFromBase64:(NSString *)base64

Parameters

base64

The function’s input data, a Base-64-encoded string.

Return Value

The Base-64-decoded form of base64, contained in an NSData instance.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield the input string.

Expression usage

^dataFromBase64(aHR0cDovL3RlY2guZ2lsdC5jb20v)

The expression above returns an NSData instance containing the bytes representing the UTF-8 encoded string, “http://tech.gilt.com/”.

Declared In

MBMLEncodingFunctions.h

Hexadecimal string encoding & decoding

+ hexStringFromData:

Converts an NSData instance into a hexadecimal string representing its byte content.

+ (id)hexStringFromData:(NSData *)data

Parameters

data

The function’s input data.

Return Value

The hexadecimal representation of the input data.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield an NSData instance.

Expression usage

The expression:

^hexStringFromData($myData)

would return a string that contains the hexadecimal representation of the bytes within the NSData instance yielded by the MBML expression “$myData”.

Declared In

MBMLEncodingFunctions.h

+ dataFromHexString:

Decodes a hexadecimal string representation of data, and returns the resulting NSData instance.

+ (id)dataFromHexString:(NSString *)hexString

Parameters

hexString

The function’s input data, a hexadecimal-encoded string.

Return Value

The hexadecimal-decoded form of hexString, contained in an NSData instance.

Discussion

This Mockingbird function accepts a single expression parameter that is expected to yield the input string.

Expression usage

^dataFromHexString(687474703a2f2f746563682e67696c742e636f6d2f)

The expression above returns an NSData instance containing the bytes representing the UTF-8 encoded string, “http://tech.gilt.com/”.

Declared In

MBMLEncodingFunctions.h