idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
38,500 | public function getLastExecutionTime ( $ jobCode ) { if ( $ this -> isDisabled ( $ jobCode ) ) { return false ; } $ schedules = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) ; $ schedules -> getSelect ( ) -> limit ( 1 ) -> order ( 'executed_at DESC' ) ; $ schedules -> addFieldToFilter ( array ( 'status' ) ,... | Get last execution time |
38,501 | public function dateDiff ( $ time1 , $ time2 = null ) { if ( is_null ( $ time2 ) ) { $ time2 = Mage :: getModel ( 'core/date' ) -> date ( ) ; } $ time1 = strtotime ( $ time1 ) ; $ time2 = strtotime ( $ time2 ) ; return $ time2 - $ time1 ; } | Diff between to times ; |
38,502 | public function isDisabled ( $ jobCode ) { $ job = Mage :: getModel ( 'aoe_scheduler/job' ) -> load ( $ jobCode ) ; return ( $ job -> getJobCode ( ) && ! $ job -> getIsActive ( ) ) ; } | Check if job code is disabled in configuration |
38,503 | public function sendErrorMail ( Aoe_Scheduler_Model_Schedule $ schedule , $ error ) { if ( ! Mage :: getStoreConfig ( self :: XML_PATH_EMAIL_RECIPIENT ) ) { return ; } $ recipients = $ this -> trimExplode ( ',' , Mage :: getStoreConfig ( self :: XML_PATH_EMAIL_RECIPIENT ) , true ) ; $ translate = Mage :: getSingleton (... | Send error mail |
38,504 | public function getCallBack ( $ runModel ) { if ( ! preg_match ( Mage_Cron_Model_Observer :: REGEX_RUN_MODEL , ( string ) $ runModel , $ run ) ) { Mage :: throwException ( Mage :: helper ( 'cron' ) -> __ ( 'Invalid model/method definition, expecting "model/class::method", got "' . $ runModel . '" instead.' ) ) ; } if (... | Get callback from runModel |
38,505 | public function validateCronExpression ( $ cronExpression ) { try { $ schedule = Mage :: getModel ( 'cron/schedule' ) ; $ schedule -> setCronExpr ( $ cronExpression ) ; } catch ( Exception $ e ) { return false ; } return true ; } | Validate cron expression |
38,506 | public function runningAsConfiguredUser ( $ useRunningUser = true ) { if ( ! $ this -> getShowUserCronMessage ( ) ) { return true ; } $ getUserMethod = ( $ useRunningUser ) ? 'getRunningUser' : 'getLastRunUser' ; return ( $ this -> { $ getUserMethod } ( ) === $ this -> getConfiguredUser ( ) ) ; } | Check the configuration value for which user the cron should be run as and check if it matches the actual user . Skip if the warning should be ignored . |
38,507 | public function checkCachePrefix ( ) { $ dbCachePrefix = $ this -> getDbCachePrefix ( ) ; if ( empty ( $ dbCachePrefix ) ) { return true ; } $ localXmlCachePrefix = Mage :: app ( ) -> getCache ( ) -> getOption ( 'cache_id_prefix' ) ; return ( $ localXmlCachePrefix == $ dbCachePrefix ) ; } | Check if the cache prefix from the database matches the cache prefix from the local . xml file |
38,508 | public static function configure ( ) { static $ configured = false ; if ( ! $ configured ) { register_shutdown_function ( array ( 'Aoe_Scheduler_Helper_GracefulDead' , 'beforeDyingShutdown' ) ) ; if ( extension_loaded ( 'pcntl' ) && function_exists ( 'pcntl_signal' ) ) { declare ( ticks = 1 ) ; pcntl_signal ( SIGINT , ... | Configure graceful dead |
38,509 | public function usageHelp ( ) { $ help = 'Available actions: ' . "\n" ; $ methods = get_class_methods ( $ this ) ; foreach ( $ methods as $ method ) { if ( substr ( $ method , - 6 ) == 'Action' ) { $ help .= ' --action ' . substr ( $ method , 0 , - 6 ) ; $ helpMethod = $ method . 'Help' ; if ( method_exists ( $ this... | Retrieve Usage Help Message |
38,510 | public function lastRunAction ( ) { $ code = $ this -> getArg ( 'code' ) ; if ( empty ( $ code ) ) { echo "\nNo code found!\n\n" ; echo $ this -> usageHelp ( ) ; exit ( 1 ) ; } $ collection = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) ; $ collection -> addFieldToFilter ( 'job_code' , $ code ) -> addField... | Returns the timestamp of the last run of a given job |
38,511 | public function scheduleNowAction ( ) { $ code = $ this -> getArg ( 'code' ) ; if ( empty ( $ code ) ) { echo "\nNo code found!\n\n" ; echo $ this -> usageHelp ( ) ; exit ( 1 ) ; } $ allowedCodes = Mage :: getSingleton ( 'aoe_scheduler/job' ) -> getResource ( ) -> getJobCodes ( ) ; if ( ! in_array ( $ code , $ allowedC... | Schedule a job now |
38,512 | public function runNowAction ( ) { $ code = $ this -> getArg ( 'code' ) ; if ( empty ( $ code ) ) { echo "\nNo code found!\n\n" ; echo $ this -> usageHelp ( ) ; exit ( 1 ) ; } $ allowedCodes = Mage :: getSingleton ( 'aoe_scheduler/job' ) -> getResource ( ) -> getJobCodes ( ) ; if ( ! in_array ( $ code , $ allowedCodes ... | Run a job now |
38,513 | public function waitAction ( ) { $ timeout = $ this -> getArg ( 'timeout' ) ? $ this -> getArg ( 'timeout' ) : 60 ; $ startTime = time ( ) ; $ sleepBetweenPolls = 2 ; $ processManager = Mage :: getModel ( 'aoe_scheduler/processManager' ) ; do { sleep ( $ sleepBetweenPolls ) ; $ aliveSchedules = 0 ; echo "Currently runn... | Active wait until no schedules are running |
38,514 | public function skipMissedSchedules ( ) { $ schedules = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) -> addFieldToFilter ( 'status' , Aoe_Scheduler_Model_Schedule :: STATUS_PENDING ) -> addFieldToFilter ( 'scheduled_at' , array ( 'lt' => strftime ( '%Y-%m-%d %H:%M:%S' , time ( ) ) ) ) -> addOrder ( 'schedu... | Mark missed schedule records by changing status |
38,515 | public function getPendingSchedules ( array $ whitelist = array ( ) , array $ blacklist = array ( ) ) { $ pendingSchedules = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) -> addFieldToFilter ( 'status' , Aoe_Scheduler_Model_Schedule :: STATUS_PENDING ) -> addFieldToFilter ( 'scheduled_at' , array ( 'lt' => ... | Get pending schedules |
38,516 | public function getScheduleForAlwaysJob ( $ jobCode , $ reason = null ) { $ processManager = Mage :: getModel ( 'aoe_scheduler/processManager' ) ; if ( ! $ processManager -> isJobCodeRunning ( $ jobCode ) ) { $ ts = strftime ( '%Y-%m-%d %H:%M:00' , time ( ) ) ; $ schedule = Mage :: getModel ( 'cron/schedule' ) ; $ sche... | Get job for task marked as always |
38,517 | public function deleteDuplicates ( ) { $ cron_schedule = Mage :: getSingleton ( 'core/resource' ) -> getTableName ( 'cron_schedule' ) ; $ conn = Mage :: getSingleton ( 'core/resource' ) -> getConnection ( 'core_read' ) ; $ results = $ conn -> fetchAll ( " SELECT GROUP_CONCAT(schedule_id) AS ids, CONCAT(job_code... | Delete duplicate crons |
38,518 | public function flushSchedules ( $ jobCode = null ) { $ pendingSchedules = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) -> addFieldToFilter ( 'status' , Aoe_Scheduler_Model_Schedule :: STATUS_PENDING ) -> addFieldToFilter ( 'scheduled_at' , array ( 'gt' => strftime ( '%Y-%m-%d %H:%M:%S' , time ( ) ) ) ) ->... | Flushed all future pending schedules . |
38,519 | public function deleteAll ( ) { $ schedules = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) ; foreach ( $ schedules as $ key => $ schedule ) { $ schedule -> delete ( ) ; } Mage :: app ( ) -> saveCache ( 0 , Mage_Cron_Model_Observer :: CACHE_KEY_LAST_SCHEDULE_GENERATE_AT , array ( 'crontab' ) , null ) ; retu... | Delete all schedules |
38,520 | public function generateSchedulesForJob ( Aoe_Scheduler_Model_Job $ job ) { if ( ! $ job -> canBeScheduled ( ) ) { return $ this ; } $ exists = array ( ) ; foreach ( $ this -> getPendingSchedules ( array ( $ job -> getJobCode ( ) ) , array ( ) ) as $ schedule ) { $ exists [ $ schedule -> getJobCode ( ) . '/' . $ schedu... | Generate jobs for config information |
38,521 | protected function _filterStoreCondition ( $ collection , $ column ) { if ( ! $ value = $ column -> getFilter ( ) -> getValue ( ) ) { return ; } $ this -> getCollection ( ) -> addStoreFilter ( $ value ) ; } | Helper function to add store filter condition |
38,522 | protected function hourFloor ( $ timestamp ) { return mktime ( date ( 'H' , $ timestamp ) , 0 , 0 , date ( 'n' , $ timestamp ) , date ( 'j' , $ timestamp ) , date ( 'Y' , $ timestamp ) ) ; } | Return the last full houd |
38,523 | protected function hourCeil ( $ timestamp ) { return mktime ( date ( 'H' , $ timestamp ) + 1 , 0 , 0 , date ( 'n' , $ timestamp ) , date ( 'j' , $ timestamp ) , date ( 'Y' , $ timestamp ) ) ; } | Returns the next full hour |
38,524 | public function getGanttDivAttributes ( Aoe_Scheduler_Model_Schedule $ schedule ) { if ( $ schedule -> getStatus ( ) == Aoe_Scheduler_Model_Schedule :: STATUS_RUNNING ) { $ duration = time ( ) - strtotime ( $ schedule -> getStarttime ( ) ) ; } else { $ duration = $ schedule -> getDuration ( ) ? $ schedule -> getDuratio... | Get attributes for div representing a gantt element |
38,525 | public function _toHtml ( ) { $ html = parent :: _toHtml ( ) ; if ( ! $ html && ! Mage :: getStoreConfigFlag ( 'dev/template/allow_symlink' ) ) { $ url = $ this -> getUrl ( 'adminhtml/system_config/edit' , array ( 'section' => 'dev' ) ) . '#dev_template' ; $ html = $ this -> __ ( 'Warning: You installed Aoe_Scheduler u... | Check if symlinks are allowed |
38,526 | protected function _initAction ( ) { if ( ! Mage :: getStoreConfigFlag ( 'system/cron/enable' ) ) { $ this -> _getSession ( ) -> addNotice ( $ this -> __ ( 'Scheduler is disabled in configuration (system/cron/enable). No schedules will be executed.' ) ) ; } else { $ this -> checkHeartbeat ( ) ; } if ( Mage :: getStoreC... | Preparing layout for output |
38,527 | protected function checkLocalCodePool ( ) { $ helper = Mage :: helper ( 'aoe_scheduler/compatibility' ) ; if ( $ helper -> oldConfigXmlExists ( ) ) { $ this -> _getSession ( ) -> addError ( $ this -> __ ( 'Looks like you have an older version of Aoe_Scheduler installed that lived in the local code pool. Please delete e... | Aoe_Scheduler used to live in the local code pool . When newer version are installed without removing the old files Aoe_Scheduler will produce fatal errors . This is an attempt to handle this a little better . |
38,528 | protected function _checkCronUser ( ) { $ helper = Mage :: helper ( 'aoe_scheduler' ) ; if ( ! $ helper -> getShowUserCronMessage ( ) ) { return ; } if ( ! $ helper -> runningAsConfiguredUser ( false ) ) { $ configuredUser = $ helper -> getConfiguredUser ( ) ; if ( ! empty ( $ configuredUser ) ) { $ this -> _getSession... | Check the user running the cron matches the configured user and if not prevented display a warning message with some CTAs |
38,529 | public function generateScheduleAction ( ) { Mage :: app ( ) -> removeCache ( Mage_Cron_Model_Observer :: CACHE_KEY_LAST_SCHEDULE_GENERATE_AT ) ; $ scheduleManager = Mage :: getModel ( 'aoe_scheduler/scheduleManager' ) ; $ scheduleManager -> generateSchedules ( ) ; $ this -> _getSession ( ) -> addSuccess ( $ this -> __... | Generate schedule now |
38,530 | protected function _initJob ( ) { $ jobCode = $ this -> getRequest ( ) -> getParam ( 'job_code' , null ) ; $ job = Mage :: getModel ( 'aoe_scheduler/job' ) -> load ( $ jobCode ) ; Mage :: register ( 'current_job_instance' , $ job ) ; return $ job ; } | Init job instance and set it to registry |
38,531 | public function editAction ( ) { $ this -> _initJob ( ) ; $ this -> _initAction ( ) -> _addBreadcrumb ( $ this -> __ ( 'Edit Job' ) , $ this -> __ ( 'Edit Job' ) ) -> _title ( $ this -> __ ( 'Edit Job' ) ) -> renderLayout ( ) ; } | Edit cron action |
38,532 | public function showUserWarningAction ( ) { Mage :: getModel ( 'core/config' ) -> saveConfig ( Aoe_Scheduler_Helper_Data :: XML_PATH_SHOW_WRONG_USER_MSG , 1 ) ; $ this -> _getSession ( ) -> addSuccess ( $ this -> __ ( 'You will be alerted about misconfigured cron users again.' ) ) ; $ this -> _redirectReferer ( ) ; } | Show the misconfigured cron user warning message again |
38,533 | public function hideUserWarningAction ( ) { Mage :: getModel ( 'core/config' ) -> saveConfig ( Aoe_Scheduler_Helper_Data :: XML_PATH_SHOW_WRONG_USER_MSG , 0 ) ; $ this -> _getSession ( ) -> addSuccess ( $ this -> __ ( 'We won\'t alert you about misconfigured cron users again. You can turn it back on in the scheduler co... | Don t show the misconfigured cron user warning message any more |
38,534 | public function setConfiguredUserAction ( ) { $ user = $ this -> getRequest ( ) -> getParam ( 'user' ) ; Mage :: getModel ( 'core/config' ) -> saveConfig ( Aoe_Scheduler_Helper_Data :: XML_PATH_CRON_USER , ( string ) $ user ) ; $ this -> _getSession ( ) -> addSuccess ( $ this -> __ ( 'Configured cron user updated to be... | Set the configured user to what was probably suggested |
38,535 | public function getNewEmptyItem ( ) { $ model = Mage :: getModel ( $ this -> model ) ; if ( ! $ model instanceof Aoe_Scheduler_Model_Job ) { Mage :: throwException ( sprintf ( 'Invalid model class. Expected "%s" and received "%s".' , 'Aoe_Scheduler_Model_Job' , ( is_object ( $ model ) ? get_class ( $ model ) : 'UNKNOWN... | Retrieve collection empty item |
38,536 | public function addItem ( Varien_Object $ item ) { if ( ! $ item instanceof Aoe_Scheduler_Model_Job ) { Mage :: throwException ( sprintf ( 'Invalid model class. Expected "%s" and received "%s".' , 'Aoe_Scheduler_Model_Job' , get_class ( $ item ) ) ) ; } $ jobCode = $ item -> getJobCode ( ) ; if ( ! $ jobCode ) { Mage :... | Adding item to item array |
38,537 | public function getColumnValues ( $ column ) { $ values = array ( ) ; foreach ( $ this as $ item ) { $ values [ ] = $ item -> getDataUsingMethod ( $ column ) ; } return $ values ; } | Retrieve field values from all items |
38,538 | public function getItemsByColumnValue ( $ column , $ value ) { $ items = array ( ) ; foreach ( $ this as $ item ) { if ( $ item -> getDataUsingMethod ( $ column ) == $ value ) { $ items [ ] = $ item ; } } return $ items ; } | Search all items by field value |
38,539 | public function getItemByColumnValue ( $ column , $ value ) { foreach ( $ this as $ item ) { if ( $ item -> getDataUsingMethod ( $ column ) == $ value ) { return $ item ; } } return null ; } | Search first item by field value |
38,540 | public function setDataToAll ( $ key , $ value = null ) { if ( is_array ( $ key ) ) { foreach ( $ key as $ k => $ v ) { $ this -> setDataToAll ( $ k , $ v ) ; } return $ this ; } foreach ( $ this -> getItems ( ) as $ item ) { $ item -> setDataUsingMethod ( $ key , $ value ) ; } return $ this ; } | Setting data for all collection items |
38,541 | protected function _toOptionArray ( $ valueField = 'job_code' , $ labelField = 'name' , $ additional = array ( ) ) { $ options = array ( ) ; $ additional [ 'value' ] = $ valueField ; $ additional [ 'label' ] = $ labelField ; foreach ( $ this as $ item ) { $ data = array ( ) ; foreach ( $ additional as $ code => $ field... | Convert items array to array for select options |
38,542 | protected function _toOptionHash ( $ valueField = 'job_code' , $ labelField = 'name' ) { $ res = array ( ) ; foreach ( $ this as $ item ) { $ res [ $ item -> getDataUsingMethod ( $ valueField ) ] = $ item -> getDataUsingMethod ( $ labelField ) ; } return $ res ; } | Convert items array to hash for select options |
38,543 | public function getAllRunningSchedules ( $ host = null ) { $ collection = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) ; $ collection -> addFieldToFilter ( 'status' , Aoe_Scheduler_Model_Schedule :: STATUS_RUNNING ) ; if ( ! is_null ( $ host ) ) { $ collection -> addFieldToFilter ( 'host' , $ host ) ; } re... | Get all schedules running on this server |
38,544 | public function getAllKillRequests ( $ host = null ) { $ collection = $ this -> getAllRunningSchedules ( $ host ) ; $ collection -> addFieldToFilter ( 'kill_request' , array ( 'lt' => strftime ( '%Y-%m-%d %H:%M:00' , time ( ) + 60 ) ) ) ; return $ collection ; } | Get all schedules marked as to be killed |
38,545 | public function isJobCodeRunning ( $ jobCode , $ ignoreId = null ) { $ collection = Mage :: getModel ( 'cron/schedule' ) -> getCollection ( ) -> addFieldToFilter ( 'status' , Aoe_Scheduler_Model_Schedule :: STATUS_RUNNING ) -> addFieldToFilter ( 'job_code' , $ jobCode ) ; if ( ! is_null ( $ ignoreId ) ) { $ collection ... | Check if there s already a job running with the given code |
38,546 | public function checkRunningJobs ( ) { $ maxJobRuntime = intval ( Mage :: getStoreConfig ( self :: XML_PATH_MAX_JOB_RUNTIME ) ) ; if ( $ maxJobRuntime ) { foreach ( $ this -> getAllRunningSchedules ( gethostname ( ) ) as $ schedule ) { if ( $ schedule -> isAlive ( ) ) { if ( $ schedule -> getDuration ( ) > $ maxJobRunt... | Check running jobs |
38,547 | public function dispatch ( Varien_Event_Observer $ observer ) { if ( ! Mage :: getStoreConfigFlag ( 'system/cron/enable' ) ) { return ; } $ processManager = Mage :: getModel ( 'aoe_scheduler/processManager' ) ; $ processManager -> watchdog ( ) ; $ scheduleManager = Mage :: getModel ( 'aoe_scheduler/scheduleManager' ) ;... | Process cron queue Generate tasks schedule Cleanup tasks schedule |
38,548 | public function dispatchAlways ( Varien_Event_Observer $ observer ) { if ( ! Mage :: getStoreConfigFlag ( 'system/cron/enable' ) ) { return ; } $ processManager = Mage :: getModel ( 'aoe_scheduler/processManager' ) ; $ processManager -> watchdog ( ) ; $ scheduleManager = Mage :: getModel ( 'aoe_scheduler/scheduleManage... | Process cron queue for tasks marked as always |
38,549 | public function getEncryptionPublicKey ( ) : EncryptionPublicKey { $ ed25519_pk = $ this -> getRawKeyMaterial ( ) ; $ x25519_pk = \ sodium_crypto_sign_ed25519_pk_to_curve25519 ( $ ed25519_pk ) ; return new EncryptionPublicKey ( new HiddenString ( $ x25519_pk ) ) ; } | Get an encryption public key from a signing public key . |
38,550 | public static function isLibsodiumSetupCorrectly ( bool $ echo = false ) : bool { if ( ! \ extension_loaded ( 'sodium' ) ) { if ( $ echo ) { echo "You do not have the sodium extension enabled.\n" ; } return false ; } $ major = \ SODIUM_LIBRARY_MAJOR_VERSION ; if ( $ major < 10 ) { if ( $ echo ) { echo 'Halite needs lib... | Is Libsodium set up correctly? Use this to verify that you can use the newer versions of Halite correctly . |
38,551 | public static function checksum ( $ filePath , Key $ key = null , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { if ( $ filePath instanceof ReadOnlyFile ) { $ pos = $ filePath -> getPos ( ) ; $ filePath -> reset ( 0 ) ; $ checksum = self :: checksumData ( $ filePath , $ key , $ encoding ) ; $ filePath -> rese... | Calculate the BLAKE2b - 512 checksum of a file . This method doesn t load the entire file into memory . You may optionally supply a key to use in the BLAKE2b hash . |
38,552 | public static function encrypt ( $ input , $ output , EncryptionKey $ key ) : int { if ( ( \ is_resource ( $ input ) || \ is_string ( $ input ) || ( $ input instanceof ReadOnlyFile ) ) && ( \ is_resource ( $ output ) || \ is_string ( $ output ) || ( $ output instanceof MutableFile ) ) ) { try { if ( $ input instanceof ... | Encrypt a file using symmetric authenticated encryption . |
38,553 | public static function decrypt ( $ input , $ output , EncryptionKey $ key ) : bool { if ( ( \ is_resource ( $ input ) || \ is_string ( $ input ) || ( $ input instanceof ReadOnlyFile ) ) && ( \ is_resource ( $ output ) || \ is_string ( $ output ) || ( $ output instanceof MutableFile ) ) ) { try { if ( $ input instanceof... | Decrypt a file using symmetric - key authenticated encryption . |
38,554 | public static function unseal ( $ input , $ output , EncryptionSecretKey $ secretKey ) : bool { if ( ( \ is_resource ( $ input ) || \ is_string ( $ input ) || ( $ input instanceof ReadOnlyFile ) ) && ( \ is_resource ( $ output ) || \ is_string ( $ output ) || ( $ output instanceof MutableFile ) ) ) { try { if ( $ input... | Decrypt a file using anonymous public - key encryption . Ciphertext integrity is still assured thanks to the Encrypt - then - MAC construction . |
38,555 | public static function verify ( $ filename , SignaturePublicKey $ publicKey , string $ signature , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : bool { if ( $ filename instanceof ReadOnlyFile ) { $ pos = $ filename -> getPos ( ) ; $ filename -> reset ( 0 ) ; $ verified = self :: verifyData ( $ filename , $ publicKey ... | Verify a digital signature for a file . |
38,556 | protected static function checksumData ( StreamInterface $ fileStream , Key $ key = null , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { $ config = self :: getConfig ( Halite :: HALITE_VERSION_FILE , 'checksum' ) ; if ( $ key instanceof AuthenticationKey ) { $ state = \ sodium_crypto_generichash_init ( $ key... | Calculate the BLAKE2b checksum of the contents of a file |
38,557 | protected static function decryptData ( ReadOnlyFile $ input , MutableFile $ output , EncryptionKey $ key ) : bool { $ input -> reset ( 0 ) ; if ( $ input -> getSize ( ) < Halite :: VERSION_TAG_LEN ) { throw new InvalidMessage ( "Input file is too small to have been encrypted by Halite." ) ; } $ header = $ input -> rea... | Decrypt the contents of a file . |
38,558 | protected static function sealData ( ReadOnlyFile $ input , MutableFile $ output , EncryptionPublicKey $ publicKey ) : int { $ ephemeralKeyPair = KeyFactory :: generateEncryptionKeyPair ( ) ; $ ephSecret = $ ephemeralKeyPair -> getSecretKey ( ) ; $ ephPublic = $ ephemeralKeyPair -> getPublicKey ( ) ; unset ( $ ephemera... | Seal the contents of a file . |
38,559 | protected static function unsealData ( ReadOnlyFile $ input , MutableFile $ output , EncryptionSecretKey $ secretKey ) : bool { $ publicKey = $ secretKey -> derivePublicKey ( ) ; if ( $ input -> getSize ( ) < Halite :: VERSION_TAG_LEN ) { throw new InvalidMessage ( "Input file is too small to have been encrypted by Hal... | Unseal the contents of a file . |
38,560 | protected static function signData ( ReadOnlyFile $ input , SignatureSecretKey $ secretKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { $ checksum = self :: checksumData ( $ input , $ secretKey -> derivePublicKey ( ) , true ) ; return AsymmetricCrypto :: sign ( $ checksum , $ secretKey , $ encoding ) ; } | Sign the contents of a file |
38,561 | protected static function verifyData ( ReadOnlyFile $ input , SignaturePublicKey $ publicKey , string $ signature , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : bool { $ checksum = self :: checksumData ( $ input , $ publicKey , true ) ; return AsymmetricCrypto :: verify ( $ checksum , $ publicKey , $ signature , $ e... | Verify the contents of a file |
38,562 | protected static function splitKeys ( Key $ master , string $ salt , Config $ config ) : array { $ binary = $ master -> getRawKeyMaterial ( ) ; return [ Util :: hkdfBlake2b ( $ binary , \ SODIUM_CRYPTO_SECRETBOX_KEYBYTES , ( string ) $ config -> HKDF_SBOX , $ salt ) , Util :: hkdfBlake2b ( $ binary , \ SODIUM_CRYPTO_AU... | Split a key using HKDF - BLAKE2b |
38,563 | final private static function streamEncrypt ( ReadOnlyFile $ input , MutableFile $ output , EncryptionKey $ encKey , string $ nonce , string $ mac , Config $ config ) : int { $ initHash = $ input -> getHash ( ) ; $ size = $ input -> getSize ( ) ; $ written = 0 ; while ( $ input -> remainingBytes ( ) > 0 ) { $ read = $ ... | Stream encryption - Do not call directly |
38,564 | final private static function streamDecrypt ( ReadOnlyFile $ input , MutableFile $ output , EncryptionKey $ encKey , string $ nonce , string $ mac , Config $ config , array & $ chunk_macs ) : bool { $ start = $ input -> getPos ( ) ; $ cipher_end = $ input -> getSize ( ) - ( int ) $ config -> MAC_SIZE ; $ input -> reset... | Stream decryption - Do not call directly |
38,565 | final private static function streamVerify ( ReadOnlyFile $ input , $ mac , Config $ config ) : array { $ start = $ input -> getPos ( ) ; $ cipher_end = $ input -> getSize ( ) - ( int ) $ config -> MAC_SIZE ; $ input -> reset ( $ cipher_end ) ; $ stored_mac = $ input -> readBytes ( ( int ) $ config -> MAC_SIZE ) ; $ in... | Recalculate and verify the HMAC of the input file |
38,566 | public static function encryptWithAd ( HiddenString $ plaintext , EncryptionSecretKey $ ourPrivateKey , EncryptionPublicKey $ theirPublicKey , string $ additionalData = '' , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { $ ss = self :: getSharedSecret ( $ ourPrivateKey , $ theirPublicKey ) ; $ sharedSecretKey... | Encrypt with additional associated data . |
38,567 | public static function getSharedSecret ( EncryptionSecretKey $ privateKey , EncryptionPublicKey $ publicKey , bool $ get_as_object = false ) : object { if ( $ get_as_object ) { return new EncryptionKey ( new HiddenString ( \ sodium_crypto_scalarmult ( $ privateKey -> getRawKeyMaterial ( ) , $ publicKey -> getRawKeyMate... | Diffie - Hellman ECDHE etc . |
38,568 | public static function seal ( HiddenString $ plaintext , EncryptionPublicKey $ publicKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { $ sealed = \ sodium_crypto_box_seal ( $ plaintext -> getString ( ) , $ publicKey -> getRawKeyMaterial ( ) ) ; $ encoder = Halite :: chooseEncoder ( $ encoding ) ; if ( $ en... | Encrypt a message with a target users public key |
38,569 | public static function sign ( string $ message , SignatureSecretKey $ privateKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { $ signed = \ sodium_crypto_sign_detached ( $ message , $ privateKey -> getRawKeyMaterial ( ) ) ; $ encoder = Halite :: chooseEncoder ( $ encoding ) ; if ( $ encoder ) { return ( st... | Sign a message with our private key |
38,570 | public static function signAndEncrypt ( HiddenString $ message , SignatureSecretKey $ secretKey , PublicKey $ recipientPublicKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { if ( $ recipientPublicKey instanceof SignaturePublicKey ) { $ publicKey = $ recipientPublicKey -> getEncryptionPublicKey ( ) ; } els... | Sign a message then encrypt it with the recipient s public key . |
38,571 | public static function unseal ( string $ ciphertext , EncryptionSecretKey $ privateKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : HiddenString { $ decoder = Halite :: chooseEncoder ( $ encoding , true ) ; if ( $ decoder ) { try { $ ciphertext = $ decoder ( $ ciphertext ) ; } catch ( \ RangeException $ ex ) { thr... | Decrypt a sealed message with our private key |
38,572 | public static function verify ( string $ message , SignaturePublicKey $ publicKey , string $ signature , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : bool { $ decoder = Halite :: chooseEncoder ( $ encoding , true ) ; if ( $ decoder ) { $ signature = $ decoder ( $ signature ) ; } if ( Binary :: safeStrlen ( $ signatu... | Verify a signed message with the correct public key |
38,573 | public static function verifyAndDecrypt ( string $ ciphertext , SignaturePublicKey $ senderPublicKey , SecretKey $ givenSecretKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : HiddenString { if ( $ givenSecretKey instanceof SignatureSecretKey ) { $ secretKey = $ givenSecretKey -> getEncryptionSecretKey ( ) ; } else... | Decrypt a message then verify its signature . |
38,574 | public function getEncryptionSecretKey ( ) : EncryptionSecretKey { $ ed25519_sk = $ this -> getRawKeyMaterial ( ) ; $ x25519_sk = \ sodium_crypto_sign_ed25519_sk_to_curve25519 ( $ ed25519_sk ) ; return new EncryptionSecretKey ( new HiddenString ( $ x25519_sk ) ) ; } | Get an encryption secret key from a signing secret key . |
38,575 | public function getRoot ( bool $ raw = false ) : string { if ( ! $ this -> rootCalculated ) { $ this -> root = $ this -> calculateRoot ( ) ; } return $ raw ? $ this -> root : Hex :: encode ( $ this -> root ) ; } | Get the root hash of this Merkle tree . |
38,576 | public function getExpandedTree ( Node ... $ nodes ) : MerkleTree { $ thisTree = $ this -> nodes ; foreach ( $ nodes as $ node ) { $ thisTree [ ] = $ node ; } return ( new MerkleTree ( ... $ thisTree ) ) -> setHashSize ( $ this -> outputSize ) -> setPersonalizationString ( $ this -> personalization ) ; } | Merkle Trees are immutable . Return a replacement with extra nodes . |
38,577 | public function setHashSize ( int $ size ) : self { if ( $ size < \ SODIUM_CRYPTO_GENERICHASH_BYTES_MIN ) { throw new InvalidDigestLength ( \ sprintf ( 'Merkle roots must be at least %d long.' , \ SODIUM_CRYPTO_GENERICHASH_BYTES_MIN ) ) ; } if ( $ size > \ SODIUM_CRYPTO_GENERICHASH_BYTES_MAX ) { throw new InvalidDigest... | Set the hash output size . |
38,578 | public function setPersonalizationString ( string $ str = '' ) : self { if ( $ this -> personalization !== $ str ) { $ this -> rootCalculated = false ; } $ this -> personalization = $ str ; return $ this ; } | Sets the personalization string for the Merkle root calculation |
38,579 | public function close ( ) : void { if ( $ this -> closeAfter ) { $ this -> closeAfter = false ; \ fclose ( $ this -> fp ) ; \ clearstatcache ( ) ; } } | Close the file handle . |
38,580 | public function getHash ( ) : string { $ init = $ this -> pos ; \ fseek ( $ this -> fp , 0 , SEEK_SET ) ; $ h = \ sodium_crypto_generichash_init ( $ this -> hashKey , \ SODIUM_CRYPTO_GENERICHASH_BYTES_MAX ) ; for ( $ i = 0 ; $ i < $ this -> stat [ 'size' ] ; $ i += self :: CHUNK ) { if ( ( $ i + self :: CHUNK ) > $ thi... | Calculate a BLAKE2b hash of a file |
38,581 | public function writeBytes ( string $ buf , int $ num = null ) : int { unset ( $ buf ) ; unset ( $ num ) ; throw new FileAccessDenied ( 'This is a read-only file handle.' ) ; } | This is a meaningless operation for a Read - Only File! |
38,582 | public static function hash ( HiddenString $ password , EncryptionKey $ secretKey , string $ level = KeyFactory :: INTERACTIVE , string $ additionalData = '' ) : string { $ kdfLimits = KeyFactory :: getSecurityLevels ( $ level ) ; $ hashed = \ sodium_crypto_pwhash_str ( $ password -> getString ( ) , $ kdfLimits [ 0 ] ,... | Hash then encrypt a password |
38,583 | public static function needsRehash ( string $ stored , EncryptionKey $ secretKey , string $ level = KeyFactory :: INTERACTIVE , string $ additionalData = '' ) : bool { $ config = self :: getConfig ( $ stored ) ; if ( Binary :: safeStrlen ( $ stored ) < ( ( int ) $ config -> SHORTEST_CIPHERTEXT_LENGTH * 4 / 3 ) ) { thro... | Is this password hash stale? |
38,584 | public static function verify ( HiddenString $ password , string $ stored , EncryptionKey $ secretKey , string $ additionalData = '' ) : bool { $ config = self :: getConfig ( $ stored ) ; if ( Binary :: safeStrlen ( $ stored ) < ( ( int ) $ config -> SHORTEST_CIPHERTEXT_LENGTH * 4 / 3 ) ) { throw new InvalidMessage ( '... | Decrypt then verify a password |
38,585 | public function readBytes ( int $ num , bool $ skipTests = false ) : string { if ( $ num < 0 ) { throw new CannotPerformOperation ( 'num < 0' ) ; } elseif ( $ num === 0 ) { return '' ; } if ( ( $ this -> pos + $ num ) > $ this -> stat [ 'size' ] ) { throw new CannotPerformOperation ( 'Out-of-bounds read' ) ; } $ buf = ... | Read from a stream ; prevent partial reads |
38,586 | public function remainingBytes ( ) : int { $ stat = \ fstat ( $ this -> fp ) ; $ pos = \ ftell ( $ this -> fp ) ; return ( int ) ( PHP_INT_MAX & ( ( int ) $ stat [ 'size' ] - $ pos ) ) ; } | Get number of bytes remaining |
38,587 | public function writeBytes ( string $ buf , int $ num = null ) : int { $ bufSize = Binary :: safeStrlen ( $ buf ) ; if ( ! \ is_int ( $ num ) || $ num > $ bufSize ) { $ num = $ bufSize ; } if ( $ num < 0 ) { throw new CannotPerformOperation ( 'num < 0' ) ; } $ remaining = $ num ; do { if ( $ remaining <= 0 ) { break ; ... | Write to a stream ; prevent partial writes |
38,588 | public static function authenticate ( string $ message , AuthenticationKey $ secretKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { $ config = SymmetricConfig :: getConfig ( Halite :: HALITE_VERSION , 'auth' ) ; $ mac = self :: calculateMAC ( $ message , $ secretKey -> getRawKeyMaterial ( ) , $ config ) ;... | Authenticate a string |
38,589 | public static function encrypt ( HiddenString $ plaintext , EncryptionKey $ secretKey , $ encoding = Halite :: ENCODE_BASE64URLSAFE ) : string { return static :: encryptWithAd ( $ plaintext , $ secretKey , '' , $ encoding ) ; } | Encrypt a message using the Halite encryption protocol |
38,590 | public static function verify ( string $ message , AuthenticationKey $ secretKey , string $ mac , $ encoding = Halite :: ENCODE_BASE64URLSAFE , SymmetricConfig $ config = null ) : bool { $ decoder = Halite :: chooseEncoder ( $ encoding , true ) ; if ( $ decoder ) { $ mac = $ decoder ( $ mac ) ; } if ( $ config === null... | Verify the authenticity of a message given a shared MAC key |
38,591 | protected static function calculateMAC ( string $ message , string $ authKey , SymmetricConfig $ config ) : string { if ( $ config -> MAC_ALGO === 'BLAKE2b' ) { return \ sodium_crypto_generichash ( $ message , $ authKey , ( int ) $ config -> MAC_SIZE ) ; } throw new InvalidMessage ( 'Invalid Halite version' ) ; } | Calculate a MAC . This is used internally . |
38,592 | public static function intArrayToString ( array $ integers ) : string { $ args = $ integers ; foreach ( $ args as $ i => $ v ) { $ args [ $ i ] = ( int ) ( $ v & 0xff ) ; } return \ pack ( \ str_repeat ( 'C' , \ count ( $ args ) ) , ... $ args ) ; } | Convert an array of integers to a string |
38,593 | public static function safeStrcpy ( string $ string ) : string { $ length = Binary :: safeStrlen ( $ string ) ; $ return = '' ; $ chunk = $ length >> 1 ; if ( $ chunk < 1 ) { $ chunk = 1 ; } for ( $ i = 0 ; $ i < $ length ; $ i += $ chunk ) { $ return .= Binary :: safeSubstr ( $ string , $ i , $ chunk ) ; } return $ re... | PHP 7 uses interned strings . We don t want altering this one to alter the original string . |
38,594 | public static function xorStrings ( string $ left , string $ right ) : string { $ length = Binary :: safeStrlen ( $ left ) ; if ( $ length !== Binary :: safeStrlen ( $ right ) ) { throw new InvalidType ( 'Both strings must be the same length' ) ; } if ( $ length < 1 ) { return '' ; } return ( string ) ( $ left ^ $ righ... | Calculate A xor B given two binary strings of the same length . |
38,595 | protected static function getConfig ( string $ stored ) : SymmetricConfig { $ length = Binary :: safeStrlen ( $ stored ) ; if ( $ length < 8 ) { throw new InvalidMessage ( 'Encrypted password hash is way too short.' ) ; } if ( \ hash_equals ( Binary :: safeSubstr ( $ stored , 0 , 5 ) , Halite :: VERSION_PREFIX ) ) { $ ... | Get the configuration for this version of halite |
38,596 | public static function generateEncryptionKeyPair ( ) : EncryptionKeyPair { $ kp = \ sodium_crypto_box_keypair ( ) ; $ secretKey = \ sodium_crypto_box_secretkey ( $ kp ) ; \ sodium_memzero ( $ kp ) ; return new EncryptionKeyPair ( new EncryptionSecretKey ( new HiddenString ( $ secretKey ) ) ) ; } | Generate a key pair for public key encryption |
38,597 | public static function generateSignatureKeyPair ( ) : SignatureKeyPair { $ kp = \ sodium_crypto_sign_keypair ( ) ; $ secretKey = \ sodium_crypto_sign_secretkey ( $ kp ) ; \ sodium_memzero ( $ kp ) ; return new SignatureKeyPair ( new SignatureSecretKey ( new HiddenString ( $ secretKey ) ) ) ; } | Generate a key pair for public key digital signatures |
38,598 | public static function deriveEncryptionKeyPair ( HiddenString $ password , string $ salt , string $ level = self :: INTERACTIVE , int $ alg = SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13 ) : EncryptionKeyPair { $ kdfLimits = self :: getSecurityLevels ( $ level , $ alg ) ; if ( Binary :: safeStrlen ( $ salt ) !== \ SODIUM_CRYPTO... | Derive a key pair for public key encryption from a password and salt |
38,599 | public static function deriveSignatureKeyPair ( HiddenString $ password , string $ salt , string $ level = self :: INTERACTIVE , int $ alg = SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13 ) : SignatureKeyPair { $ kdfLimits = self :: getSecurityLevels ( $ level , $ alg ) ; if ( Binary :: safeStrlen ( $ salt ) !== \ SODIUM_CRYPTO_P... | Derive a key pair for public key signatures from a password and salt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.