/src/mozilla-central/dom/security/SRIMetadata.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_SRIMetadata_h |
8 | | #define mozilla_dom_SRIMetadata_h |
9 | | |
10 | | #include "nsTArray.h" |
11 | | #include "nsString.h" |
12 | | #include "SRICheck.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | class SRIMetadata final |
18 | | { |
19 | | friend class SRICheck; |
20 | | |
21 | | public: |
22 | | static const uint32_t MAX_ALTERNATE_HASHES = 256; |
23 | | static const int8_t UNKNOWN_ALGORITHM = -1; |
24 | | |
25 | | /** |
26 | | * Create an empty metadata object. |
27 | | */ |
28 | | SRIMetadata() : mAlgorithmType(UNKNOWN_ALGORITHM), mEmpty(true) {} |
29 | | |
30 | | /** |
31 | | * Split a string token into the components of an SRI metadata |
32 | | * attribute. |
33 | | */ |
34 | | explicit SRIMetadata(const nsACString& aToken); |
35 | | |
36 | | /** |
37 | | * Returns true when this object's hash algorithm is weaker than the |
38 | | * other object's hash algorithm. |
39 | | */ |
40 | | bool operator<(const SRIMetadata& aOther) const; |
41 | | |
42 | | /** |
43 | | * Not implemented. Should not be used. |
44 | | */ |
45 | | bool operator>(const SRIMetadata& aOther) const; |
46 | | |
47 | | /** |
48 | | * Add another metadata's hash to this one. |
49 | | */ |
50 | | SRIMetadata& operator+=(const SRIMetadata& aOther); |
51 | | |
52 | | /** |
53 | | * Returns true when the two metadata use the same hash algorithm. |
54 | | */ |
55 | | bool operator==(const SRIMetadata& aOther) const; |
56 | | |
57 | | bool IsEmpty() const { return mEmpty; } |
58 | 0 | bool IsMalformed() const { return mHashes.IsEmpty() || mAlgorithm.IsEmpty(); } |
59 | 0 | bool IsAlgorithmSupported() const { return mAlgorithmType != UNKNOWN_ALGORITHM; } |
60 | 0 | bool IsValid() const { return !IsMalformed() && IsAlgorithmSupported(); } |
61 | | |
62 | 0 | uint32_t HashCount() const { return mHashes.Length(); } |
63 | | void GetHash(uint32_t aIndex, nsCString* outHash) const; |
64 | 0 | void GetAlgorithm(nsCString* outAlg) const { *outAlg = mAlgorithm; } |
65 | | void GetHashType(int8_t* outType, uint32_t* outLength) const; |
66 | | |
67 | | const nsString& GetIntegrityString() const |
68 | | { |
69 | | return mIntegrityString; |
70 | | } |
71 | | |
72 | | private: |
73 | | nsTArray<nsCString> mHashes; |
74 | | nsString mIntegrityString; |
75 | | nsCString mAlgorithm; |
76 | | int8_t mAlgorithmType; |
77 | | bool mEmpty; |
78 | | }; |
79 | | |
80 | | } // namespace dom |
81 | | } // namespace mozilla |
82 | | |
83 | | #endif // mozilla_dom_SRIMetadata_h |