isset( $config['lo_id'] ) ? (int) $config['lo_id'] : 0, 'route' => isset( $config['route_email'] ) ? (string) $config['route_email'] : '', 'page' => isset( $config['page_id'] ) ? (int) $config['page_id'] : 0, ) ); $b64 = rtrim( strtr( base64_encode( $payload ), '+/', '-_' ), '=' ); return $b64 . '.' . \Mapp\Security\Secret::hmac( 'config', $b64 ); } /** * @param string $signed Signed config. * @return array lo_id, route_email, page_id (empty values when invalid). */ public static function verify( $signed ) { $empty = array( 'lo_id' => 0, 'route_email' => '', 'page_id' => 0, ); if ( ! is_string( $signed ) || false === strpos( $signed, '.' ) ) { return $empty; } list( $b64, $sig ) = explode( '.', $signed, 2 ); if ( ! hash_equals( \Mapp\Security\Secret::hmac( 'config', $b64 ), (string) $sig ) ) { return $empty; } $data = json_decode( (string) base64_decode( strtr( $b64, '-_', '+/' ) ), true ); if ( ! is_array( $data ) ) { return $empty; } return array( 'lo_id' => isset( $data['lo'] ) ? (int) $data['lo'] : 0, 'route_email' => isset( $data['route'] ) && is_email( $data['route'] ) ? (string) $data['route'] : '', 'page_id' => isset( $data['page'] ) ? (int) $data['page'] : 0, ); } }