Skip to content

Commit

Permalink
Add new methods CCT and CDD
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriy Svirin committed Feb 22, 2021
1 parent 4f3a87f commit 0081ced
Show file tree
Hide file tree
Showing 54 changed files with 7,533 additions and 431 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
composer.lock
vendor

# Testing env variables.
envs.local.php

.php_cs.cache
.phpunit.result.cache
.phpunit.result.cache
21 changes: 0 additions & 21 deletions .php_cs.dist

This file was deleted.

2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"license": "MIT",
"require": {
"php": "^7.2 || ^8",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-openssl": "*",
"ext-zip": "*",
"ext-zlib": "*",
"ext-json": "*",
"phpseclib/phpseclib": "~2.0"
Expand Down
15 changes: 0 additions & 15 deletions envs-example.local.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/Builders/MutableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public function addTransactionPhase(string $transactionPhase): MutableBuilder
return $this;
}

public function addSegmentNumber(int $segmentNumber): MutableBuilder
{
$xmlSegmentNumber = $this->dom->createElement('SegmentNumber');
$xmlSegmentNumber->setAttribute('lastSegment', 'true');
$xmlSegmentNumber->nodeValue = (string)$segmentNumber;

$this->instance->appendChild($xmlSegmentNumber);

return $this;
}

public function getInstance(): DOMElement
{
return $this->instance;
Expand Down
1 change: 1 addition & 0 deletions src/Builders/OrderDetailsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class OrderDetailsBuilder

const ORDER_ATTRIBUTE_DZNNN = 'DZNNN';
const ORDER_ATTRIBUTE_DZHNN = 'DZHNN';
const ORDER_ATTRIBUTE_OZHNN = 'OZHNN';

/**
* @var DOMElement
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/StaticBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ public function addBank(KeyRing $keyRing, string $algorithm = 'sha256'): StaticB
$xmlAuthentication = $this->dom->createElement('Authentication');
$xmlAuthentication->setAttribute('Version', $keyRing->getBankSignatureXVersion());
$xmlAuthentication->setAttribute('Algorithm', sprintf('http://www.w3.org/2001/04/xmlenc#%s', $algorithm));
$certificateXDigest = $this->cryptService->calculateDigest($signatureX, $algorithm);
$certificateXDigest = $this->cryptService->calculateDigest($signatureX, $algorithm, true);
$xmlAuthentication->nodeValue = base64_encode($certificateXDigest);
$xmlBankPubKeyDigests->appendChild($xmlAuthentication);

// Add Encryption to BankPubKeyDigests.
$xmlEncryption = $this->dom->createElement('Encryption');
$xmlEncryption->setAttribute('Version', $keyRing->getBankSignatureEVersion());
$xmlEncryption->setAttribute('Algorithm', sprintf('http://www.w3.org/2001/04/xmlenc#%s', $algorithm));
$certificateEDigest = $this->cryptService->calculateDigest($signatureE, $algorithm);
$certificateEDigest = $this->cryptService->calculateDigest($signatureE, $algorithm, true);
$xmlEncryption->nodeValue = base64_encode($certificateEDigest);
$xmlBankPubKeyDigests->appendChild($xmlEncryption);

Expand Down
17 changes: 17 additions & 0 deletions src/Contexts/RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class RequestContext
*/
private $receiptCode;

/**
* @var int
*/
private $segmentNumber;

/**
* @var string
*/
Expand Down Expand Up @@ -225,6 +230,18 @@ public function getReceiptCode(): string
return $this->receiptCode;
}

public function setSegmentNumber(int $segmentNumber): RequestContext
{
$this->segmentNumber = $segmentNumber;

return $this;
}

public function getSegmentNumber(): int
{
return $this->segmentNumber;
}

public function setTransactionId(string $transactionId): RequestContext
{
$this->transactionId = $transactionId;
Expand Down
37 changes: 31 additions & 6 deletions src/Contracts/Crypt/AESInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,55 @@ interface AESInterface
{

/**
* Sets the key length
*
* Valid key lengths are 128, 192, and 256. If the length is less than 128, it will be rounded up to
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
*
* @param int $length
*
* @return void
* @see \phpseclib\Crypt\AES::setKeyLength()
*/
public function setKeyLength($length);
public function setKeyLength(int $length);

/**
* Sets the key.
*
* Rijndael supports five different key lengths, AES only supports three.
*
* @param string $key
*
* @return void
* @see \phpseclib\Crypt\AES::setKey()
*/
public function setKey($key);
public function setKey(string $key);

/**
* Sets the initialization vector. (optional)
*
* SetIV is not required when self::MODE_ECB (or ie for AES: AES::MODE_ECB) is being used.
* If not explicitly set, it'll be assumed to be all zero's.
*
* @param string $iv
*
* @return void
*/
public function setIV(string $iv);

/**
* Decrypts a message.
*
* If strlen($ciphertext) is not a multiple of the block size, null bytes will be added
* to the end of the string until it is.
*
* @param string $ciphertext
*
* @return string $plaintext
* @see \phpseclib\Crypt\AES::decrypt()
*/
public function decrypt($ciphertext);
public function decrypt(string $ciphertext);

/**
* Set options.
*
* @param mixed $options
*
* @return void
Expand Down
104 changes: 104 additions & 0 deletions src/Contracts/Crypt/ASN1Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace AndrewSvirin\Ebics\Contracts\Crypt;

use AndrewSvirin\Ebics\Models\Crypt\ASN1;

/**
* Crypt ASN1 representation.
*
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Andrew Svirin
*/
interface ASN1Interface
{
/**
* Load OIDs
*
* Load the relevant OIDs for a particular ASN.1 semantic mapping.
*
* @param array $oids
*
* @return void
*/
public function loadOIDs(array $oids);

/**
* Parse BER-encoding
*
* Serves a similar purpose to openssl's asn1parse
*
* @param string $encoded Bytes.
*
* @return array
*/
public function decodeBER(string $encoded);

/**
* ASN.1 Map
*
* Provides an ASN.1 semantic mapping ($mapping) from a parsed BER-encoding to a human readable format.
*
* "Special" mappings may be applied on a per tag-name basis via $special.
*
* @param array $decoded
* @param array $mapping
* @param array $special
*
* @return array|string|false|null
*/
public function asn1map(array $decoded, array $mapping, array $special = []);

/**
* Load filters
*
* @param array $filters
*
* @return void
*/
public function loadFilters(array $filters);

/**
* ASN.1 Encode
*
* DER-encodes an ASN.1 semantic mapping ($mapping). Some libraries would probably call this function
* an ASN.1 compiler.
*
* "Special" mappings can be applied via $special.
*
* @param string|array $source
* @param array $mapping
* @param array $special
*
* @return string
*/
public function encodeDER($source, array $mapping, array $special = []);

/**
* String type conversion
*
* This is a lazy conversion, dealing only with character size.
* No real conversion table is used.
*
* @param string $in
* @param int $from
* @param int $to
*
* @return string|false
*/
public function convert(string $in, int $from = ASN1::TYPE_UTF8_STRING, int $to = ASN1::TYPE_UTF8_STRING);

/**
* Get property ANYmap.
*
* @return array
*/
public function getANYmap();

/**
* Get property stringTypeSize.
*
* @return array
*/
public function getStringTypeSize();
}
Loading

0 comments on commit 0081ced

Please # to comment.