Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/kerberos/model/kerberos_flags.rb
Views: 11766
# -*- coding: binary -*-12module Rex3module Proto4module Kerberos5module Model6# Represents KerberosFlags.7# https://www.rfc-editor.org/rfc/rfc4120.txt8class KerberosFlags9# @return [Integer] the integer value of the kerberos flags10attr_reader :value1112# @param [Integer] value the numerical value of the flags13# @raise [ArgumentError] if any of the parameters are of an invalid type14def initialize(value)15raise ArgumentError, 'Invalid value' unless value.is_a?(Integer)16@value = value17end1819# @param [Array<Integer,Rex::Proto::Kerberos::Model::KdcOptionFlags>] flags an array of numerical values representing flags20# @return [Rex::Proto::Kerberos::Model::KdcOptionFlags]21def self.from_flags(flags)22value = 023flags.each do |flag|24value |= 1 << (31 - flag)25end2627new(value)28end2930def to_i31@value32end3334# @param [Integer,Rex::Proto::Kerberos::Model::KdcOptionFlags] flag the numerical value of the flag to test for.35# @return [Boolean] whether the flag is present within the current KdcOptionFlags36def include?(flag)37((value >> (31 - flag)) & 1) == 138end3940# @return [Array<String>] The enabled flag names41def enabled_flag_names42sorted_flag_names = self.class.constants.sort_by { |name| self.class.const_get(name) }43enabled_flag_names = sorted_flag_names.select { |flag| include?(self.class.const_get(flag)) }4445enabled_flag_names46end4748def self.name(value)49constants.select { |c| c.upcase == c }.find { |c| const_get(c) == value }50end5152# Override the equality test for KdcOptionFlags. Equality is53# always tested against the #value of the KdcOptionFlags.54#55# @param other [Object] The object to test equality against56# @raise [ArgumentError] if the other object is not either another KdcOptionFlags or a Integer57# @return [Boolean] whether the equality test passed58def ==(other)59if other.is_a? self.class60value == other.value61elsif other.is_a? Integer62value == other63elsif other.nil?64false65else66raise ArgumentError, "Cannot compare a #{self.class} to a #{other.class}"67end68end6970alias === ==71end72end73end74end75end767778