File indexing completed on 2024-12-22 05:36:34

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Crypt
0017  * @subpackage Rsa
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @category   Zend
0025  * @package    Zend_Crypt
0026  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0027  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0028  */
0029 class Zend_Crypt_Rsa_Key implements Countable
0030 {
0031     /**
0032      * @var string
0033      */
0034     protected $_pemString = null;
0035 
0036     /**
0037      * Bits, key string and type of key
0038      *
0039      * @var array
0040      */
0041     protected $_details = array();
0042 
0043     /**
0044      * Key Resource
0045      *
0046      * @var resource
0047      */
0048     protected $_opensslKeyResource = null;
0049 
0050     /**
0051      * Retrieves key resource
0052      *
0053      * @return resource
0054      */
0055     public function getOpensslKeyResource()
0056     {
0057         return $this->_opensslKeyResource;
0058     }
0059 
0060     /**
0061      * @return string
0062      * @throws Zend_Crypt_Exception
0063      */
0064     public function toString()
0065     {
0066         if (!empty($this->_pemString)) {
0067             return $this->_pemString;
0068         } elseif (!empty($this->_certificateString)) {
0069             return $this->_certificateString;
0070         }
0071         /**
0072          * @see Zend_Crypt_Exception
0073          */
0074         // require_once 'Zend/Crypt/Exception.php';
0075         throw new Zend_Crypt_Exception('No public key string representation is available');
0076     }
0077 
0078     /**
0079      * @return string
0080      */
0081     public function __toString()
0082     {
0083         return $this->toString();
0084     }
0085 
0086     public function count()
0087     {
0088         return $this->_details['bits'];
0089     }
0090 
0091     public function getType()
0092     {
0093         return $this->_details['type'];
0094     }
0095 }