File: BlockMode.php

package info (click to toggle)
horde2 2.2.8-1sarge3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,832 kB
  • ctags: 2,897
  • sloc: php: 12,784; sh: 954; sql: 149; makefile: 104; perl: 97; xml: 24; pascal: 6
file content (64 lines) | stat: -rw-r--r-- 2,023 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
 * The Horde_Cipher_BlockMode:: class provides a common abstracted
 * interface to various block mode handlers for cyphers.
 *
 * $Horde: horde/lib/Cipher/BlockMode.php,v 1.4.2.4 2003/01/05 02:54:11 jon Exp $
 *
 * Copyright 2002-2003 Mike Cochrane <mike@graftonhall.co.nz>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Mike Cochrane <mike@graftonhall.co.nz>
 * @version $Revision: 1.4.2.4 $
 * @since   Horde 2.2
 * @package horde.cipher
 */
class Horde_Cipher_BlockMode {

    /* String containing the initilization vector. */
    var $_iv = "\0\0\0\0\0\0\0\0";

    /**
     * Attempts to return a concrete CipherBlockMode instance based on $mode.
     *
     * @access public
     *
     * @param mixed $cipher           The type of concrete CipherBlockMode
     *                                subclass to return.
     * @param optional array $params  A hash containing any additional
     *                                parameters a subclass might need.
     *
     * @return object CipherBlockMode The newly created concrete Cipher
     *                                instance, or PEAR_Error on an error.
     */
    function &factory($mode, $params = null)
    {
        $mode = strtolower(basename($mode));

        if (@file_exists(dirname(__FILE__) . '/Cipher/BlockMode/' . $mode . '.php')) {
            require_once dirname(__FILE__) . '/Cipher/BlockMode/' . $mode . '.php';
        } else {
            require_once HORDE_BASE . '/lib/Cipher/BlockMode/' . $mode . '.php';
        }

        $class = 'Horde_Cipher_BlockMode_' . $mode;
        if (class_exists($class)) {
            return new $class($params);
        } else {
            return PEAR::raiseError('Class definition of ' . $class . ' not found.');
        }
    }

    /**
     * Set the iv
     *
     * @param String $iv    The new iv.
     */
    function setIV($iv)
    {
        $this->_iv = $iv;
    }

}