crypto = $cryptoObject; $this->keyRetrievalFunction = $keyRetrievalFunction; if ( $this->crypto->identity ){ $this->set( 'From', $this->crypto->identity ); } } private function get_recipient_key( $forCrypto = FALSE ){ if ( is_null( $this->recipientPubKey ) ){ if ( ! empty( $this->data['To'] ) && $this->keyRetrievalFunction ){ $this->recipientPubKey = call_user_func( $this->keyRetrievalFunction, $this->data['To'] ); } else { $this->recipientPubKey = FALSE; } } if ( ! $this->recipientPubKey ){ return FALSE; } return $this->recipientPubKey; } public function set( $name, $value = NULL, $encrypted = FALSE ){ if ( is_null( $value ) ){ unset( $this->data[ $name ] ); return; } if ( $encrypted ){ $key = $this->get_recipient_key( TRUE ); if ( $key ){ $this->set( $name, NULL ); $name .= '~'; $value = $this->crypto->encrypt( $value, $key ); } } $this->data[ $name ] = $value; } public function multiset( $namesAndValues, $encrypted = FALSE ){ foreach ( $namesAndValues as $name => $value ){ $this->set( $name, $value, $encrypted ); } } public function set_date( $time = NULL ){ $this->set( 'Date', date( 'c', $time ?? time() ) ); } public function set_recipient( $id, $pubKey = NULL ){ $this->set( 'To', $id ); if ( $pubKey ){ $this->recipientPubKey = $pubKey; } } public function set_public_key(){ $pubKey = $this->crypto->get_local_pubkey(); if ( $pubKey ){ $this->set( 'Public-Key', $pubKey ); } } public function dump(){ return yaml_emit( $this->data ); } public function dump_signed(){ $rawMessage = $this->dump(); $signature = $this->crypto->generate_signature( $rawMessage ); return "Signature: {$signature}\n{$rawMessage}"; } } // end of file outgoing_message.class.php