-
Notifications
You must be signed in to change notification settings - Fork 2
/
AttestPolicy.php
56 lines (51 loc) · 1.33 KB
/
AttestPolicy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace ParagonIE\Gossamer\Client;
/**
* Class AttestPolicy
* @package ParagonIE\Gossamer\Client
*/
class AttestPolicy
{
/* Attestation Types */
const CODE_REVIEW = 'code-review';
const REPRODUCED = 'reproduced';
const SPOT_CHECK = 'spot-check';
const SECURITY_AUDIT = 'sec-audit';
const VOTE_AGAINST = 'vote-against';
/** @var PolicyRuleInterface[] $rules */
private $rules;
/**
* AttestPolicy constructor.
* @param PolicyRuleInterface ...$rules
*/
public function __construct(PolicyRuleInterface ...$rules)
{
$this->rules = $rules;
}
/**
* @param PolicyRuleInterface $rule
* @return self
*/
public function addRule(PolicyRuleInterface $rule)
{
$this->rules []= $rule;
return $this;
}
/**
* Does this set of attestations for an update pass all top-level rules?
*
* @param array{attestor: string, attestation: string, ledgerhash: string}[] $attestations
* @return bool
*/
public function passes(array $attestations)
{
if (empty($this->rules)) {
return true;
}
$passesTopLevel = true;
foreach ($this->rules as $rule) {;
$passesTopLevel = $passesTopLevel && $rule->passes($attestations);
}
return $passesTopLevel;
}
}