public function testBuild() { $cipherRegistry = new CipherRegistry(); $cipherRegistry->add(new MysqlAes())->add(new NoOp()); $keySource = new ChainSource(); $profileRegistry = new ProfileRegistry(); $serializerDeserializer = new ChainSerializerDeserializer(); $this->assertEquals(new Encryptor($cipherRegistry, $keySource, $profileRegistry, $serializerDeserializer, null), $this->encryptorBuilder->build()); }
public function testBuild() { $cipher1 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn('cipher1')->getMock(); $cipher2 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn('cipher2')->getMock(); $this->builder->add($cipher1)->add($cipher2); $cipherRegistry = new CipherRegistry(); $cipherRegistry->add($cipher1)->add($cipher2); $this->assertEquals($cipherRegistry, $this->builder->build()); }
/** * @expectedException \Giftcards\Encryption\Cipher\CipherNotFoundException */ public function testGetWithMissingEncryptor() { $encryptor1Name = $this->getFaker()->unique()->word; $encryptor1 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn($encryptor1Name)->getMock(); $encryptor2Name = $this->getFaker()->unique()->word; $encryptor2 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn($encryptor2Name)->getMock(); $this->assertSame($this->registry, $this->registry->add($encryptor1)); $this->assertSame($this->registry, $this->registry->add($encryptor2)); $this->assertSame($encryptor1, $this->registry->get($encryptor1Name)); $this->registry->get($this->getFaker()->unique()->word); }
public function testDecrypt() { $cipherText1 = $this->getFaker()->unique()->word; $plainText1 = $this->getFaker()->unique()->word; $this->cipherRegistry->get($this->cipher1Name)->shouldReceive('decipher')->once()->with($cipherText1, $this->keySource->get($this->key1Name))->andReturn($plainText1); $this->serializerDeserializer->shouldReceive('deserialize')->once()->with($cipherText1)->andReturn(new CipherText($cipherText1, $this->profileRegistry->get($this->profile1Name))); $this->assertEquals($plainText1, $this->encryptor->decrypt($cipherText1)); $this->cipherRegistry->get($this->cipher1Name)->shouldReceive('decipher')->once()->with($cipherText1, $this->keySource->get($this->key1Name))->andReturn($plainText1); $this->serializerDeserializer->shouldReceive('deserialize')->once()->with($cipherText1)->andReturn(new CipherText($cipherText1, $this->profileRegistry->get($this->profile1Name))); $this->assertEquals($plainText1, $this->encryptor->decrypt($cipherText1, $this->profile1Name)); $cipherText2 = $this->getFaker()->unique()->word; $plainText2 = $this->getFaker()->unique()->word; $this->cipherRegistry->get($this->cipher2Name)->shouldReceive('decipher')->once()->with($cipherText2, $this->keySource->get($this->key2Name))->andReturn($plainText2); $this->assertEquals($plainText2, $this->encryptor->decrypt(new CipherText($cipherText2, $this->profileRegistry->get($this->profile2Name)))); }
public function all() { foreach ($this->ciphers as $name => $cipher) { $this->load($name); } return parent::all(); }