Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/reports/security/finding_signature.rb')
-rw-r--r--lib/gitlab/ci/reports/security/finding_signature.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/gitlab/ci/reports/security/finding_signature.rb b/lib/gitlab/ci/reports/security/finding_signature.rb
new file mode 100644
index 00000000000..d1d7ef5c377
--- /dev/null
+++ b/lib/gitlab/ci/reports/security/finding_signature.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Reports
+ module Security
+ class FindingSignature
+ include VulnerabilityFindingSignatureHelpers
+
+ attr_accessor :algorithm_type, :signature_value
+
+ def initialize(params = {})
+ @algorithm_type = params.dig(:algorithm_type)
+ @signature_value = params.dig(:signature_value)
+ end
+
+ def signature_sha
+ Digest::SHA1.digest(signature_value)
+ end
+
+ def signature_hex
+ signature_sha.unpack1("H*")
+ end
+
+ def to_hash
+ {
+ algorithm_type: algorithm_type,
+ signature_sha: signature_sha
+ }
+ end
+
+ def valid?
+ algorithm_types.key?(algorithm_type)
+ end
+
+ def eql?(other)
+ other.algorithm_type == algorithm_type &&
+ other.signature_sha == signature_sha
+ end
+
+ alias_method :==, :eql?
+ end
+ end
+ end
+ end
+end