cellog          Mon Mar 26 00:00:55 2007 UTC

  Modified files:              
    /pecl/phar  TODO phar.c phar_internal.h phar_object.c 
  Log:
  [DOC]
  implement setSignatureAlgorithm() and add class constants Phar::MD5, 
Phar::SHA1, Phar::SHA256, Phar::SHA512, Phar::PGP
  
http://cvs.php.net/viewvc.cgi/pecl/phar/TODO?r1=1.31&r2=1.32&diff_format=u
Index: pecl/phar/TODO
diff -u pecl/phar/TODO:1.31 pecl/phar/TODO:1.32
--- pecl/phar/TODO:1.31 Sun Mar 25 21:43:48 2007
+++ pecl/phar/TODO      Mon Mar 26 00:00:55 2007
@@ -40,6 +40,8 @@
  * [optional] Phar->rollback() to abort a write transaction
  * implement GPG signing
  X add SHA-2 (256, 512) support [Marcus]
+ X setSignatureAlgorithm() and Phar::MD5 Phar::SHA1 Phar::SHA256 Phar::SHA512 
Phar::PGP to
+   choose the kind of signature to use (PGP falls back to SHA1) [Greg]
  * ability to match files containing a metadata key 
opendir('phar://a.phar/?mime-type=image/jpeg')
    or foreach ($p->match('mime-type', 'image/jpeg') as $file)
  * Phar::copy($from, $to);
http://cvs.php.net/viewvc.cgi/pecl/phar/phar.c?r1=1.185&r2=1.186&diff_format=u
Index: pecl/phar/phar.c
diff -u pecl/phar/phar.c:1.185 pecl/phar/phar.c:1.186
--- pecl/phar/phar.c:1.185      Sun Mar 25 23:42:48 2007
+++ pecl/phar/phar.c    Mon Mar 26 00:00:55 2007
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar.c,v 1.185 2007/03/25 23:42:48 cellog Exp $ */
+/* $Id: phar.c,v 1.186 2007/03/26 00:00:55 cellog Exp $ */
 
 #define PHAR_MAIN
 #include "phar_internal.h"
@@ -2522,9 +2522,7 @@
                        efree(archive->signature);
                }
                
-               switch(PHAR_SIG_USE) {
-               case PHAR_SIG_PGP:
-                       /* TODO: currently fall back to sha1,later do both */
+               switch(archive->sig_flags) {
 #if HAVE_HASH_EXT
                case PHAR_SIG_SHA512: {
                        unsigned char digest[64];
@@ -2566,6 +2564,8 @@
                        }
                        return EOF;
 #endif
+               case PHAR_SIG_PGP:
+                       /* TODO: currently fall back to sha1,later do both */
                default:
                case PHAR_SIG_SHA1: {
                        unsigned char digest[20];
@@ -3376,7 +3376,7 @@
        php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
        php_info_print_table_row(2, "Phar EXT version", PHAR_EXT_VERSION_STR);
        php_info_print_table_row(2, "Phar API version", PHAR_API_VERSION_STR);
-       php_info_print_table_row(2, "CVS revision", "$Revision: 1.185 $");
+       php_info_print_table_row(2, "CVS revision", "$Revision: 1.186 $");
        php_info_print_table_row(2, "gzip compression", 
 #if HAVE_ZLIB
                "enabled");
http://cvs.php.net/viewvc.cgi/pecl/phar/phar_internal.h?r1=1.26&r2=1.27&diff_format=u
Index: pecl/phar/phar_internal.h
diff -u pecl/phar/phar_internal.h:1.26 pecl/phar/phar_internal.h:1.27
--- pecl/phar/phar_internal.h:1.26      Sun Mar 25 21:43:48 2007
+++ pecl/phar/phar_internal.h   Mon Mar 26 00:00:55 2007
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar_internal.h,v 1.26 2007/03/25 21:43:48 helly Exp $ */
+/* $Id: phar_internal.h,v 1.27 2007/03/26 00:00:55 cellog Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -83,8 +83,6 @@
 #define PHAR_SIG_SHA512           0x0004
 #define PHAR_SIG_PGP              0x0010
 
-#define PHAR_SIG_USE  PHAR_SIG_SHA1
-
 /* flags byte for each file adheres to these bitmasks.
    All unused values are reserved */
 #define PHAR_ENT_COMPRESSION_MASK 0x0000F000
http://cvs.php.net/viewvc.cgi/pecl/phar/phar_object.c?r1=1.43&r2=1.44&diff_format=u
Index: pecl/phar/phar_object.c
diff -u pecl/phar/phar_object.c:1.43 pecl/phar/phar_object.c:1.44
--- pecl/phar/phar_object.c:1.43        Sun Mar 25 21:43:48 2007
+++ pecl/phar/phar_object.c     Mon Mar 26 00:00:55 2007
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar_object.c,v 1.43 2007/03/25 21:43:48 helly Exp $ */
+/* $Id: phar_object.c,v 1.44 2007/03/26 00:00:55 cellog Exp $ */
 
 #include "phar_internal.h"
 
@@ -350,6 +350,51 @@
 }
 /* }}} */
 
+/* {{{ proto array Phar::setSignatureAlgorithm(int sigtype)
+ * set the signature algorithm for a phar and apply it.  The
+ * signature algorithm must be one of Phar::MD5, Phar::SHA1,
+ * Phar::SHA256 or Phar::SHA512
+ */
+PHP_METHOD(Phar, setSignatureAlgorithm)
+{
+       long algo;
+       char *error;
+       PHAR_ARCHIVE_OBJECT();
+       
+       if (PHAR_G(readonly)) {
+               zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 
TSRMLS_CC,
+                       "Cannot change stub, phar is read-only");
+       }
+
+       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() 
TSRMLS_CC, "l", &algo) != SUCCESS) {
+               return;
+       }
+
+       switch (algo) {
+               case PHAR_SIG_SHA256 :
+               case PHAR_SIG_SHA512 :
+#if !HAVE_HASH_EXT
+                       
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
+                               "SHA-256 and SHA-512 signatures are only 
supported if the hash extension is enabled");
+#endif
+               case PHAR_SIG_MD5 :
+               case PHAR_SIG_SHA1 :
+               case PHAR_SIG_PGP :
+                       phar_obj->arc.archive->sig_flags = algo;
+                       phar_obj->arc.archive->is_modified = 1;
+
+                       phar_flush(phar_obj->arc.archive, 0, 0, &error 
TSRMLS_CC);
+                       if (error) {
+                               
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error);
+                               efree(error);
+                       }
+               default :
+                       
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
+                               "Unknown signature algorithm specified");
+       }
+}
+/* }}} */
+
 /* {{{ proto array Phar::getSupportedSignatures()
  * Return array of supported signature types
  */
@@ -1208,6 +1253,7 @@
        PHP_ME(Phar, isBuffering,           NULL,                      
ZEND_ACC_PUBLIC)
        PHP_ME(Phar, setMetadata,           arginfo_entry_setMetadata, 
ZEND_ACC_PUBLIC)
        PHP_ME(Phar, setStub,               arginfo_phar_setStub,      
ZEND_ACC_PUBLIC)
+       PHP_ME(Phar, setSignatureAlgorithm, arginfo_entry_setMetadata, 
ZEND_ACC_PUBLIC)
        PHP_ME(Phar, offsetExists,          arginfo_phar_offsetExists, 
ZEND_ACC_PUBLIC)
        PHP_ME(Phar, offsetGet,             arginfo_phar_offsetExists, 
ZEND_ACC_PUBLIC)
        PHP_ME(Phar, offsetSet,             arginfo_phar_offsetSet,    
ZEND_ACC_PUBLIC)
@@ -1289,6 +1335,11 @@
        REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "COMPRESSED", 
PHAR_ENT_COMPRESSION_MASK)
        REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "GZ", 
PHAR_ENT_COMPRESSED_GZ)
        REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "BZ2", 
PHAR_ENT_COMPRESSED_BZ2)
+       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "MD5", PHAR_SIG_MD5)
+       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "SHA1", PHAR_SIG_SHA1)
+       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "SHA256", 
PHAR_SIG_SHA256)
+       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "SHA512", 
PHAR_SIG_SHA512)
+       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "PGP", PHAR_SIG_PGP)
 }
 /* }}} */
 

Reply via email to