Completed
Push — master ( 1a59c2...c73113 )
by Florent
02:55
created

Recipient::createRecipient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Object;
13
14
/**
15
 * Class EncryptionInstruction.
16
 */
17
final class Recipient implements RecipientInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    private $headers = [];
23
24
    /**
25
     * @var null|string
26
     */
27
    private $encrypted_key = null;
28
29
    /**
30
     * @var \Jose\Object\JWKInterface
31
     */
32
    private $recipient_key = null;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public static function createRecipientFromLoadedJWE(array $headers, $encrypted_key)
38
    {
39
        $recipient = new self();
40
        $recipient->headers = $headers;
41
        $recipient->encrypted_key = $encrypted_key;
42
43
        return $recipient;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public static function createRecipient(JWKInterface $recipient_key, array $headers = [])
50
    {
51
        $recipient = new self();
52
        $recipient->headers = $headers;
53
        $recipient->recipient_key = $recipient_key;
54
55
        return $recipient;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getHeaders()
62
    {
63
        return $this->headers;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getHeader($key)
70
    {
71
        if ($this->hasHeader($key)) {
72
            return $this->headers[$key];
73
        }
74
        throw new \InvalidArgumentException(sprintf('The header "%s" does not exist.', $key));
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function hasHeader($key)
81
    {
82
        return array_key_exists($key, $this->headers);
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function getEncryptedKey()
89
    {
90
        return $this->encrypted_key;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function getRecipientKey()
97
    {
98
        return $this->recipient_key;
99
    }
100
}
101