]> granicus.if.org Git - php/commitdiff
[DOC]
authorGreg Beaver <cellog@php.net>
Mon, 26 Mar 2007 00:00:56 +0000 (00:00 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 26 Mar 2007 00:00:56 +0000 (00:00 +0000)
implement setSignatureAlgorithm() and add class constants Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, Phar::PGP

ext/phar/TODO
ext/phar/phar.c
ext/phar/phar_internal.h
ext/phar/phar_object.c

index 5ab7a3c3f83b45f7b9da986362a4a2970cdc6b9c..c5cd45520401069e8e968a858acf0aa2b3b6d894 100644 (file)
@@ -40,6 +40,8 @@ Version 1.1.0
  * [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);
index 76d753a6e0f3bb2d044e064afa65ad3a56b0ce71..df7bd2545165c3365ef9240f1d1055cdf8f107b7 100644 (file)
@@ -2522,9 +2522,7 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **err
                        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 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **err
                        }
                        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];
index 6bb532c92af23307b64dea44dcd361e26c9cdef1..2a5c43e1f7ee24fd6a8e2a5dff78fc5d92ed665a 100755 (executable)
@@ -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
index 746de8f24db6bea1a5f3a447fd9ed1190565b353..ae69c1ef8e041d65fc52a3ac56fc9c14f324d966 100755 (executable)
@@ -350,6 +350,51 @@ PHP_METHOD(Phar, setStub)
 }
 /* }}} */
 
+/* {{{ 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 @@ zend_function_entry php_archive_methods[] = {
        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 @@ void phar_object_init(TSRMLS_D) /* {{{ */
        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)
 }
 /* }}} */