summaryrefslogtreecommitdiff
path: root/fake-service/lib/pixelated_service/security_casing.rb
blob: 6e2a77e588ae51ca72013e98c5cc212db37035d7 (plain)
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

module PixelatedService
  class SecurityCasing < Struct.new(:imprints, :locks)
    def to_json(*args)
      { imprints: self.imprints, locks: self.locks }.to_json(*args)
    end

    def +(other)
      imprints = self.imprints + other.imprints
      locks = self.locks + other.locks
      SecurityCasing.new(imprints, locks)
    end

    class Key < Struct.new :longid, :fingerprint, :user_ids, :connected_contacts, :state, :size, :algorithm, :trust, :validity
      VALID_STATES = [:valid, :expired, :revoked]
      VALID_TRUST = [:unknown, :no_trust, :marginal, :full, :ultimate]

      def to_json(*args)
        { longid: self.longid,
          fingerprint: self.fingerprint,
          user_ids: self.user_ids,
          connected_contacts: self.connected_contacts,
          state: self.state,
          size: self.size,
          algorithm: self.algorithm,
          trust: self.trust,
          validity: self.validity }.to_json(*args)
      end
    end

    # Signature
    class Imprint < Struct.new :seal, :imprint_timestamp, :algorithm, :state
      VALID_STATES = [:valid, :invalid, :no_match, :from_expired, :from_revoked]

      def to_json(*args)
        { seal: self.seal,
          imprint_timestamp: self.imprint_timestamp,
          algorithm: self.algorithm,
          state: self.state }.to_json(*args)
      end
    end

    # Encryption
    class Lock < Struct.new :key, :state, :algorithm, :key_specified_in_lock
      VALID_STATES = [:valid, :failure, :no_private_key]

      def to_json(*args)
        { state: self.state,
          algorithm: self.algorithm,
          key: self.key,
          key_specified_in_lock: self.key_specified_in_lock }.to_json(*args)
      end
    end
  end
end