1<?php
2
3/**
4 * This file is part of the FreeDSx SASL package.
5 *
6 * (c) Chad Sikorra <Chad.Sikorra@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace FreeDSx\Sasl\Encoder;
13
14use FreeDSx\Sasl\Message;
15use FreeDSx\Sasl\SaslContext;
16
17/**
18 * Responsible for encoding / decoding ANONYMOUS messages.
19 *
20 * @author Chad Sikorra <Chad.Sikorra@gmail.com>
21 */
22class AnonymousEncoder implements EncoderInterface
23{
24    /**
25     * {@inheritDoc}
26     */
27    public function encode(Message $message, SaslContext $context): string
28    {
29        if ($message->has('trace')) {
30            return $message->get('trace');
31        }
32
33        return '';
34    }
35
36    /**
37     * {@inheritDoc}
38     */
39    public function decode(string $data, SaslContext $context): Message
40    {
41        $message = new Message();
42
43        if($data !== '') {
44            $message->set('trace', $data);
45        }
46
47        return $message;
48    }
49}
50