PHP Classes

File: src/BlindIndex.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Cipher Sweet   src/BlindIndex.php   Download  
File: src/BlindIndex.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Cipher Sweet
Encrypt data in away that can be searched
Author: By
Last change:
Date: 5 years ago
Size: 2,397 bytes
 

Contents

Class file image Download
<?php
namespace ParagonIE\CipherSweet;

use
ParagonIE\CipherSweet\Contract\TransformationInterface;

/**
 * Class BlindIndex
 * @package ParagonIE\CipherSweet
 */
class BlindIndex
{
   
/**
     * @var bool $fastHash
     */
   
protected $fastHash;

   
/**
     * @var array $hashConfig
     */
   
protected $hashConfig;

   
/**
     * @var string $name
     */
   
protected $name;

   
/**
     * @var int $outputLength
     */
   
protected $filterBits = 256;

   
/**
     * @var array<int, TransformationInterface> $transformations
     */
   
protected $transformations;

   
/**
     * BlindIndex constructor.
     *
     * @param string $name
     * @param array<int, TransformationInterface> $transformations
     * @param int $filterBits
     * @param bool $fastHash
     * @param array $hashConfig
     */
   
public function __construct(
       
$name,
        array
$transformations = [],
       
$filterBits = 256,
       
$fastHash = false,
        array
$hashConfig = []
    ) {
       
$this->name = $name;
       
$this->transformations = $transformations;
       
$this->filterBits = $filterBits;
       
$this->fastHash = $fastHash;
       
$this->hashConfig = $hashConfig;
    }

   
/**
     * @param TransformationInterface $tf
     * @return self
     */
   
public function addTransformation(TransformationInterface $tf)
    {
       
$this->transformations[] = $tf;
        return
$this;
    }

   
/**
     * @return string
     */
   
public function getName()
    {
        return
$this->name;
    }

   
/**
     * @return bool
     */
   
public function getFastHash()
    {
        return
$this->fastHash;
    }

   
/**
     * @return array
     */
   
public function getHashConfig()
    {
        return
$this->hashConfig;
    }

   
/**
     * @return int
     */
   
public function getFilterBitLength()
    {
        return
$this->filterBits;
    }

   
/**
     * @param string $input
     * @return string
     */
   
public function getTransformed($input)
    {
        if (empty(
$this->transformations)) {
            return
$input;
        }
       
/** @var string $output */
       
$output = $input;
        foreach (
$this->transformations as $tf) {
            if (
$tf instanceof TransformationInterface) {
               
/** @var string $output */
               
$output = $tf($output);
            }
        }
        return
$output;
    }
}