diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 03:09:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 03:09:12 +0300 |
commit | 6168721025dd8e98caeb2bf6844273e6690eaf69 (patch) | |
tree | 8c4fb20d793669e488a739bc9951dab8b363eed4 /lib/gitlab/database | |
parent | a89cb5cbdd832d4d9e80517973aceda6bc0a3856 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database')
-rw-r--r-- | lib/gitlab/database/x509_serial_number_attribute.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/gitlab/database/x509_serial_number_attribute.rb b/lib/gitlab/database/x509_serial_number_attribute.rb new file mode 100644 index 00000000000..e12f64787e7 --- /dev/null +++ b/lib/gitlab/database/x509_serial_number_attribute.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Gitlab + module Database + # Class for casting binary data to int. + # + # Using X509SerialNumberAttribute allows you to store X509 certificate + # serial number values as binary while still using integer to access them. + # rfc 5280 - 4.1.2.2 Serial number (20 octets is the maximum), could be: + # - 1461501637330902918203684832716283019655932542975 + # - 0xffffffffffffffffffffffffffffffffffffffff + class X509SerialNumberAttribute < ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bytea + PACK_FORMAT = 'H*' + + def deserialize(value) + value = super(value) + value ? value.unpack1(PACK_FORMAT).to_i : nil + end + + def serialize(value) + arg = value ? [value.to_s].pack(PACK_FORMAT) : nil + super(arg) + end + end + end +end |