Skip to content

Commit 9fed295

Browse files
committed
Methods documentation.
1 parent 99cf235 commit 9fed295

55 files changed

Lines changed: 3207 additions & 550 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
## 3.1
22

3-
* Documentation detailization.
4-
* Safety improvements.
3+
* Safety & Stability & Documentation improvements.
54

65
## 3.0
76

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace EbicsApi\Ebics\Contracts;
4+
5+
use DOMDocument;
6+
use DOMNode;
7+
use EbicsApi\Ebics\Exceptions\EbicsException;
8+
9+
/**
10+
* Authentication Signature Handler interface.
11+
*
12+
* Handles the creation and insertion of the `AuthSignature` XML element
13+
* into EBICS request documents. This signature authenticates the
14+
* request using the user's X (transaction signing) signature.
15+
*
16+
* EBICS Protocol Context:
17+
* The AuthSignature is an XML Digital Signature (XML-DSig) that proves
18+
* the authenticity of an EBICS request. It is inserted after the `<header>`
19+
* element and signs all XML elements marked with `authenticate="true"`.
20+
*
21+
* The signature process:
22+
* 1. Canonicalize the signed info section (XML-C14N)
23+
* 2. Compute SHA-256 digest of the canonicalized data
24+
* 3. Encrypt the digest with the user's X private key (RSA)
25+
* 4. Embed the signature value in the `<ds:SignatureValue>` element
26+
*
27+
* Different EBICS versions use different signature algorithms:
28+
* - EBICS 2.4/2.5: RSA-PKCS#1 v1.5 with SHA-256
29+
* - EBICS 3.0: May use RSA-PSS with SHA-256
30+
*
31+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
32+
* @author Andrew Svirin
33+
*/
34+
interface AuthSignatureHandlerInterface
35+
{
36+
/**
37+
* Add the AuthSignature element and its children to the request DOM.
38+
*
39+
* Signs all elements with attribute `authenticate="true"` and inserts
40+
* the completed AuthSignature block after the Header section.
41+
*
42+
* The method performs the following steps:
43+
* 1. Creates the `<AuthSignature>` element
44+
* 2. Builds `<ds:SignedInfo>` with canonicalization and signature methods
45+
* 3. Computes the digest value for all authenticated elements
46+
* 4. Encrypts the signed info hash with the user's X private key
47+
* 5. Embeds the signature value
48+
*
49+
* @param DOMDocument $dom The request DOM document to sign
50+
* @param DOMNode|null $xmlRequestHeader Optional header element to insert after.
51+
* If null, the handler locates the Header automatically.
52+
*
53+
* @return void
54+
*
55+
* @throws EbicsException If signature creation fails
56+
*/
57+
public function handle(DOMDocument $dom, ?DOMNode $xmlRequestHeader = null): void;
58+
}

src/Contracts/BankLetter/FormatterInterface.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,52 @@
55
use EbicsApi\Ebics\Models\BankLetter;
66

77
/**
8-
* EBICS formatter for bank letter.
8+
* Bank Letter Formatter interface.
9+
*
10+
* Defines the contract for formatting {@see BankLetter} objects into
11+
* human-readable output (e.g., plain text, HTML, PDF-ready markup).
12+
*
13+
* EBICS Protocol Context:
14+
* A bank letter (also called an "EBICS initialization letter") is a
15+
* document that contains the cryptographic parameters of an EBICS
16+
* setup, including:
17+
* - Hash values of user signatures (A, E, X) for verification
18+
* - Bank identification details (host ID, URL, country)
19+
* - User identification (partner ID, user ID)
20+
* - Public key fingerprints
21+
*
22+
* The bank letter is typically printed and sent by postal mail or
23+
* secure fax to the bank as part of the INI/HIA initialization
24+
* process, allowing the bank to verify the hash values before
25+
* activating the EBICS connection.
926
*
1027
* @license http://www.opensource.org/licenses/mit-license.html MIT License
1128
* @author Andrew Svirin
1229
*/
1330
interface FormatterInterface
1431
{
15-
1632
/**
17-
* Format bank letter to printable.
33+
* Format a bank letter into a printable string representation.
34+
*
35+
* Transforms the BankLetter model into a human-readable format
36+
* suitable for printing or display. The output format depends on
37+
* the specific formatter implementation (text, HTML, etc.).
1838
*
19-
* @param BankLetter $bankLetter
39+
* @param BankLetter $bankLetter The bank letter model to format
2040
*
21-
* @return string
41+
* @return string The formatted bank letter ready for printing or display
2242
*/
2343
public function format(BankLetter $bankLetter): string;
2444

2545
/**
26-
* Set translations.
46+
* Set custom translations for the formatted output.
47+
*
48+
* Allows overriding the default labels/headers in the bank letter
49+
* with locale-specific translations. Translation keys are implementation-
50+
* dependent.
2751
*
28-
* @param array<string, string> $translations
52+
* @param array<string, string> $translations Associative array mapping
53+
* translation keys to translated strings
2954
*
3055
* @return void
3156
*/

src/Contracts/BankLetter/HashGeneratorInterface.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,40 @@
55
use EbicsApi\Ebics\Contracts\SignatureInterface;
66

77
/**
8-
* EBICS Generate hash for bank letter.
9-
* Strategy pattern.
8+
* Bank Letter Hash Generator interface.
9+
*
10+
* Generates cryptographic hash values for signature keys to be
11+
* included in the {@see \EbicsApi\Ebics\Models\BankLetter} for
12+
* bank verification.
13+
*
14+
* EBICS Protocol Context:
15+
* During the EBICS initialization process (INI/HIA/H3K), the client
16+
* generates public/private key pairs and sends the public keys to
17+
* the bank. The bank letter contains hash values (fingerprints) of
18+
* these public keys, which the bank uses to verify that the keys
19+
* received electronically match the keys documented in the printed
20+
* letter.
21+
*
22+
* This interface uses the Strategy pattern, allowing different hash
23+
* algorithms (SHA-256, SHA-512, etc.) to be plugged in depending
24+
* on the signature version and bank requirements.
1025
*
1126
* @license http://www.opensource.org/licenses/mit-license.html MIT License
1227
* @author Andrew Svirin
1328
*/
1429
interface HashGeneratorInterface
1530
{
16-
1731
/**
18-
* Generate hash.
32+
* Generate a hash (fingerprint) for the given signature's public key.
33+
*
34+
* Computes a cryptographic hash of the public key associated with
35+
* the provided signature. This hash is included in the bank letter
36+
* for manual verification by the bank.
1937
*
20-
* @param SignatureInterface $signature
38+
* @param SignatureInterface $signature The signature whose public key
39+
* hash should be generated
2140
*
22-
* @return string
41+
* @return string The hexadecimal hash string (fingerprint)
2342
*/
2443
public function generate(SignatureInterface $signature): string;
2544
}

src/Contracts/BufferInterface.php

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,93 +3,120 @@
33
namespace EbicsApi\Ebics\Contracts;
44

55
/**
6-
* Buffer class interface.
6+
* Buffer interface.
7+
*
8+
* Provides a stream-based buffer for reading and writing data during
9+
* EBICS operations. This interface abstracts PHP stream operations
10+
* and is primarily used for handling large order data that may exceed
11+
* memory limits when processed as a single string.
12+
*
13+
* The buffer supports standard stream operations (open, close, read, write,
14+
* seek) as well as stream filter application for on-the-fly data
15+
* transformation (e.g., compression, encoding).
16+
*
17+
* EBICS Protocol Context:
18+
* Large order data (e.g., batch payment files) are often streamed rather
19+
* than loaded into memory. The buffer enables efficient handling of:
20+
* - Upload order data segmented into chunks
21+
* - Download order data reassembled from segments
22+
* - ZIP compression/decompression on the fly via stream filters
723
*
824
* @license http://www.opensource.org/licenses/mit-license.html MIT License
925
* @author Andrew Svirin
1026
*/
1127
interface BufferInterface
1228
{
29+
/**
30+
* Default read length in bytes for buffer read operations.
31+
*/
1332
const DEFAULT_READ_LENGTH = 1024;
1433

1534
/**
16-
* Open buffer.
35+
* Open the buffer with the specified mode.
36+
*
37+
* Initializes the underlying stream resource for reading and/or writing.
38+
* Common modes: 'r' (read), 'w' (write), 'r+' (read/write).
1739
*
18-
* @param string $mode
40+
* @param string $mode Stream open mode (same as PHP fopen modes)
1941
*
2042
* @return void
2143
*/
2244
public function open(string $mode): void;
2345

2446
/**
25-
* Close buffer.
47+
* Close the buffer and release the underlying stream resource.
2648
*
2749
* @return void
2850
*/
2951
public function close(): void;
3052

3153
/**
32-
* Reset pointer.
54+
* Reset the stream pointer to the beginning of the buffer.
3355
*
3456
* @return void
3557
*/
3658
public function rewind(): void;
3759

3860
/**
39-
* Write to buffer.
61+
* Write a string to the buffer at the current position.
4062
*
41-
* @param string $string
63+
* @param string $string The data to write
4264
*
4365
* @return void
4466
*/
4567
public function write(string $string): void;
4668

4769
/**
48-
* Read from buffer.
70+
* Read data from the buffer at the current position.
4971
*
50-
* @param int|null $length
72+
* If no length is specified, reads up to DEFAULT_READ_LENGTH bytes.
5173
*
52-
* @return string
74+
* @param int|null $length Number of bytes to read (defaults to DEFAULT_READ_LENGTH)
75+
*
76+
* @return string The data read from the buffer
5377
*/
5478
public function read(?int $length = null): string;
5579

5680
/**
57-
* Read from buffer full content.
81+
* Read the entire buffer content from the current position to EOF.
5882
*
59-
* @return string
83+
* @return string The full remaining content of the buffer
6084
*/
6185
public function readContent(): string;
6286

6387
/**
64-
* Is end of file.
88+
* Check if the stream pointer has reached the end of the buffer.
6589
*
66-
* @return bool
90+
* @return bool True if the pointer is at EOF, false otherwise
6791
*/
6892
public function eof(): bool;
6993

7094
/**
71-
* Move to pointer.
95+
* Move the stream pointer to the specified byte offset.
7296
*
73-
* @param int $offset
97+
* @param int $offset The byte offset to seek to
7498
*
75-
* @return int
99+
* @return int Returns 0 on success, or -1 on failure
76100
*/
77101
public function fseek(int $offset): int;
78102

79103
/**
80-
* Apply filter.
104+
* Apply a stream filter to the buffer for data transformation.
105+
*
106+
* Filters can be used for on-the-fly compression (zlib), encoding
107+
* (convert.*), or custom data processing during read/write operations.
81108
*
82-
* @param string $filterName
83-
* @param int $mode
109+
* @param string $filterName The PHP stream filter name (e.g., 'zlib.deflate')
110+
* @param int $mode Filter mode: STREAM_FILTER_READ, STREAM_FILTER_WRITE, or STREAM_FILTER_ALL
84111
*
85112
* @return void
86113
*/
87114
public function filterAppend(string $filterName, int $mode): void;
88115

89116
/**
90-
* Length of content.
117+
* Get the total length of the buffer content in bytes.
91118
*
92-
* @return int
119+
* @return int The byte length of the buffer content
93120
*/
94121
public function length(): int;
95122
}

src/Contracts/Crypt/HashInterface.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,42 @@
33
namespace EbicsApi\Ebics\Contracts\Crypt;
44

55
/**
6-
* Crypt RSA representation.
6+
* Cryptographic Hash interface.
7+
*
8+
* Provides a unified abstraction over various hash algorithms used in
9+
* EBICS protocol operations, including SHA-256, SHA-512, and others.
10+
*
11+
* EBICS Protocol Context:
12+
* Hash functions are fundamental to EBICS security:
13+
* - Computing digests of order data for RSA signature generation (A005, A006)
14+
* - Creating transaction signatures (X002) over request headers
15+
* - Verifying data integrity during transmission
16+
*
17+
* EBICS 2.5 and 3.0 primarily use SHA-256 (256-bit) for most operations,
18+
* while A006 (RSA-PSS) may use SHA-512 for enhanced security.
719
*
820
* @license http://www.opensource.org/licenses/mit-license.html MIT License
921
* @author Andrew Svirin
1022
*/
1123
interface HashInterface
1224
{
13-
1425
/**
15-
* Compute the HMAC.
26+
* Compute the cryptographic hash of the given text.
1627
*
17-
* @param string $text
28+
* @param string $text The input data to hash
1829
*
19-
* @return string
30+
* @return string The raw binary hash output
2031
*/
2132
public function hash($text);
2233

2334
/**
24-
* Returns the hash length (in bytes)
35+
* Get the output length of the hash algorithm in bytes.
36+
*
37+
* Returns the size of the hash output (e.g., 32 bytes for SHA-256,
38+
* 64 bytes for SHA-512). This is useful for allocating buffers
39+
* and validating hash lengths.
2540
*
26-
* @return int
41+
* @return int The hash output length in bytes
2742
*/
2843
public function getLength();
2944
}

0 commit comments

Comments
 (0)