# class Cipher

An abstract cipher. More...

Contains pure virtuals
Full name | `TelEngine::Cipher`
Definition | `#include <yateclass.h>`
Inherits | TelEngine::GenObject [public ]
List of all Methods

Annotated List
Files
Globals
Hierarchy
Index

#### Public Types

- enum Direction { Bidir, Encrypt, Decrypt, }

#### Public Methods

- virtual ~Cipher ()
- virtual void* getObject (const String& name) const
- virtual bool valid (Direction dir = Bidir) const
- virtual unsigned int blockSize () const
- virtual unsigned int initVectorSize () const
- unsigned int bufferSize (unsigned int len) const
- bool bufferFull (unsigned int len) const
- virtual bool setKey (const void* key, unsigned int len, Direction dir = Bidir)
- inline bool setKey (const DataBlock& key, Direction dir = Bidir)
- virtual bool initVector (const void* vect, unsigned int len, Direction dir = Bidir)
- inline bool initVector (const DataBlock& vect, Direction dir = Bidir)
- virtual bool encrypt (void* outData, unsigned int len, const void* inpData = 0)
- inline bool encrypt (DataBlock& data)
- virtual bool decrypt (void* outData, unsigned int len, const void* inpData = 0)
- inline bool decrypt (DataBlock& data)

#### Public Static Methods

- static inline const TokenDict* directions ()
- static inline Direction direction (const char* name, Direction defdir = Bidir)

## Detailed Description

The Cipher class provides an abstraction for data encryption classes

enum Direction { Bidir, Encrypt, Decrypt, }

### Direction

Cipher direction

inline const TokenDict* directions ()

### directions

[static]

Get the dictionary of cipher directions

Returns: Pointer to the dictionary of cipher directions

inline Direction direction (const char* name, Direction defdir = Bidir)

### direction

[static]

Get a direction from the dictionary given the name

Parameters:

name | Name of the direction
defdir | Default direction to return if name is empty or unknown

Returns: Direction associated with the given name

~Cipher ()

### ~Cipher

[virtual]

Destructor

void* getObject (const String& name)

### getObject

[const virtual]

Get a pointer to a derived class given that class name

Parameters:

name | Name of the class we are asking for

Returns: Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

bool valid (Direction dir = Bidir)

### valid

[const virtual]

Check if the cipher instance is valid for a specific direction

Parameters:

dir | Direction to check

Returns: True if the cipher is able to perform operation on given direction

unsigned int blockSize ()

### blockSize

[const pure virtual]

Get the cipher block size

Returns: Cipher block size in bytes

unsigned int initVectorSize ()

### initVectorSize

[const virtual]

Get the initialization vector size

Returns: Initialization vector size in bytes, 0 if not applicable

unsigned int bufferSize (unsigned int len)

### bufferSize

[const]

Round up a buffer length to a multiple of block size

Parameters:

len | Length of data to encrypt or decrypt in bytes

Returns: Length of required buffer in bytes

bool bufferFull (unsigned int len)

### bufferFull

[const]

Check if a buffer length is multiple of block size

Parameters:

len | Length of data to encrypt or decrypt in bytes

Returns: True if buffer length is multiple of block size

bool setKey (const void* key, unsigned int len, Direction dir = Bidir)

### setKey

[pure virtual]

Set the key required to encrypt or decrypt data

Parameters:

key | Pointer to binary key data
len | Length of key in bytes
dir | Direction to set key for

Returns: True if the key was set successfully

inline bool setKey (const DataBlock& key, Direction dir = Bidir)

### setKey

Set the key required to encrypt or decrypt data

Parameters:

key | Binary key data block
dir | Direction to set key for

Returns: True if the key was set successfully

bool initVector (const void* vect, unsigned int len, Direction dir = Bidir)

### initVector

[virtual]

Set the Initialization Vector if applicable

Parameters:

vect | Pointer to binary Initialization Vector data
len | Length of Initialization Vector in bytes
dir | Direction to set the Initialization Vector for

Returns: True if the Initialization Vector was set successfully

inline bool initVector (const DataBlock& vect, Direction dir = Bidir)

### initVector

Set the Initialization Vector is applicable

Parameters:

vect | Binary Initialization Vector
dir | Direction to set the Initialization Vector for

Returns: True if the Initialization Vector was set successfully

bool encrypt (void* outData, unsigned int len, const void* inpData = 0)

### encrypt

[pure virtual]

Encrypt data

Parameters:

outData | Pointer to buffer for output (encrypted) and possibly input data
len | Length of output data, may not be multiple of block size
inpData | Pointer to buffer containing input (unencrypted) data, NULL to encrypt in place

Returns: True if data was successfully encrypted

inline bool encrypt (DataBlock& data)

### encrypt

Encrypt a DataBlock in place

Parameters:

data | Data block to encrypt

Returns: True if data was successfully encrypted

bool decrypt (void* outData, unsigned int len, const void* inpData = 0)

### decrypt

[pure virtual]

Decrypt data

Parameters:

outData | Pointer to buffer for output (decrypted) and possibly input data
len | Length of output data, may not be multiple of block size
inpData | Pointer to buffer containing input (encrypted) data, NULL to decrypt in place

Returns: True if data was successfully decrypted

inline bool decrypt (DataBlock& data)

### decrypt

Decrypt a DataBlock in place

Parameters:

data | Data block to decrypt

Returns: True if data was successfully decrypted

Generated by: paulc on bussard on Fri Dec 21 16:28:34 2012, using kdoc 2.0a54.