<commit_before># frozen_string_literal: true
require 'openssl'

module RubyScep
  class PkiMessage
    include OpenSSL::ASN1

    # get OID corresponding name http://oid-info.com/get/<the oid>
    # get possible balues for a given OID in the CMS RFC https://www.ietf.org/rfc/rfc3369.txt
    OID_MESSAGE_TYPE = '2.16.840.1.113733.1.9.2'
    OID_PKI_STATUS = '2.16.840.1.113733.1.9.3'
    OID_FAIL_INFO = '2.16.840.1.113733.1.9.4'
    OID_SENDER_NONCE = '2.16.840.1.113733.1.9.5'
    OID_RECIPIENT_NOUNCE = '2.16.840.1.113733.1.9.6'
    OID_TRANSACTION_ID = '2.16.840.1.113733.1.9.7'
    OID_EXTENSION_REQUEST = '2.16.840.1.113733.1.9.8'
    OID_SIGNED_DATA = '1.2.840.113549.1.7.2'
    OID_DATA = '1.2.840.113549.1.7.1'
    OID_ENVELOPED_DATA = '1.2.840.113549.1.7.3'
    OID_RSA_ENCRYPTION = '1.2.840.113549.1.1.1'
    OID_DES_ALGO = '1.2.840.113549.3.7'
    OID_CONTENT_TYPE = '1.2.840.113549.1.9.3'
    OID_SIGNING_TIME = '1.2.840.113549.1.9.5'
    OID_MESSAGE_DIGEST = '1.2.840.113549.1.9.4'
    OID_HASH_ALGO_IDENTIFIER = '1.3.14.3.2.26'

    # complete list of possible SCEP values can be found in CISCO's documentation
    # https://www.cisco.com/c/en/us/support/docs/security-vpn/public-key-infrastructure-pki/116167-technote-scep-00.html
    SCEP_MESSAGE_TYPES = { 'PKCSReq' => 19, 'CertRep' => 3, 'GetCertInitial' => 20, 'GetCert' => 21, 'GetCRL' => 22 }
    SCEP_PKI_STATUSES = { 'SUCCESS' => 0, 'FAILURE' => 2, 'PENDING' => 3 }
    SCEP_FAIL_INFOS = { 'badAlg' => 0, 'badMessageCheck' => 1, 'badRequest' => 2, 'badTime' => 3, 'badCertId' => 4 }

    attr_accessor :p7, :device_certificate, :enrollment_response

    def initialize(asn1, p7)
      signed_attributes = retrieve_signed_attributes(asn1)
      @message_type = SCEP_MESSAGE_TYPES.key(signed_attributes[OID_MESSAGE_TYPE].to_i)<commit_msg>Fix Typo<commit_after># frozen_string_literal: true
require 'openssl'

module RubyScep
  class PkiMessage
    include OpenSSL::ASN1

    # get OID corresponding name http://oid-info.com/get/<the oid>
    # get possible values for a given OID in the CMS RFC https://www.ietf.org/rfc/rfc3369.txt
    OID_MESSAGE_TYPE = '2.16.840.1.113733.1.9.2'
    OID_PKI_STATUS = '2.16.840.1.113733.1.9.3'
    OID_FAIL_INFO = '2.16.840.1.113733.1.9.4'
    OID_SENDER_NONCE = '2.16.840.1.113733.1.9.5'
    OID_RECIPIENT_NOUNCE = '2.16.840.1.113733.1.9.6'
    OID_TRANSACTION_ID = '2.16.840.1.113733.1.9.7'
    OID_EXTENSION_REQUEST = '2.16.840.1.113733.1.9.8'
    OID_SIGNED_DATA = '1.2.840.113549.1.7.2'
    OID_DATA = '1.2.840.113549.1.7.1'
    OID_ENVELOPED_DATA = '1.2.840.113549.1.7.3'
    OID_RSA_ENCRYPTION = '1.2.840.113549.1.1.1'
    OID_DES_ALGO = '1.2.840.113549.3.7'
    OID_CONTENT_TYPE = '1.2.840.113549.1.9.3'
    OID_SIGNING_TIME = '1.2.840.113549.1.9.5'
    OID_MESSAGE_DIGEST = '1.2.840.113549.1.9.4'
    OID_HASH_ALGO_IDENTIFIER = '1.3.14.3.2.26'

    # complete list of possible SCEP values can be found in CISCO's documentation
    # https://www.cisco.com/c/en/us/support/docs/security-vpn/public-key-infrastructure-pki/116167-technote-scep-00.html
    SCEP_MESSAGE_TYPES = { 'PKCSReq' => 19, 'CertRep' => 3, 'GetCertInitial' => 20, 'GetCert' => 21, 'GetCRL' => 22 }
    SCEP_PKI_STATUSES = { 'SUCCESS' => 0, 'FAILURE' => 2, 'PENDING' => 3 }
    SCEP_FAIL_INFOS = { 'badAlg' => 0, 'badMessageCheck' => 1, 'badRequest' => 2, 'badTime' => 3, 'badCertId' => 4 }

    attr_accessor :p7, :device_certificate, :enrollment_response

    def initialize(asn1, p7)
      signed_attributes = retrieve_signed_attributes(asn1)
      @message_type = SCEP_MESSAGE_TYPES.key(signed_attributes[OID_MESSAGE_TYPE].to_i)
{'fraction_non_alphanumeric': 0.16108497093827845, 'fraction_numerical': 0.14669249930805425, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 30, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4905153', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1636, 'n_words': 228}