Sha256: be385a3e98929e7860bb37eadfe60a78253876c1168747b734d06454067b9f0a
Contents?: true
Size: 1.98 KB
Versions: 9
Compression:
Stored size: 1.98 KB
Contents
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/utils/string_utils' require 'contrast/utils/sha256_builder' require 'yaml' module Contrast module Api module Decorators # Used to decorate the Library protobuf model to handle Gem::Specification translation module Library StringUtils = Contrast::Utils::StringUtils def self.included klass klass.extend(ClassMethods) end # Used to add class methods to the Library class on inclusion of the decorator module ClassMethods def build digest, gem_specification msg = new msg.file_path = StringUtils.force_utf8(gem_specification.name) # rubocop:disable Security/Module/Name msg.hash_code = StringUtils.force_utf8(digest) msg.version = StringUtils.force_utf8(gem_specification.version) msg.manifest = StringUtils.force_utf8(build_manifest(gem_specification)) msg.external_ms = date_to_ms(gem_specification.date) msg.internal_ms = msg.external_ms msg.url = StringUtils.force_utf8(gem_specification.homepage) msg.class_count = file_count(gem_specification.full_gem_path.to_s) msg.used_class_count = 0 msg end # These are all the code files that are located in the Gem directory loaded # by the current environment; this includes more than Ruby files def file_count path Contrast::Utils::Sha256Builder.instance.files(path).length end def build_manifest spec StringUtils.force_utf8(spec.to_yaml.to_s) rescue StandardError nil end def date_to_ms date (date.to_f * 1000.0).to_i end end end end end end Contrast::Api::Dtm::Library.include(Contrast::Api::Decorators::Library)
Version data entries
9 entries across 9 versions & 1 rubygems