<commit_before><?php

namespace X509\GeneralName;

use ASN1\Type\Primitive\OctetString;
use ASN1\Type\Tagged\ImplicitlyTaggedType;


/**
 * Implements <i>iPAddress</i> CHOICE type of <i>GeneralName</i>.
 *
 * Concrete classes <code>IPv4Address</code> and <code>IPv6Address</code>
 * furthermore implement the parsing semantics.
 *
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.6
 */
abstract class IPAddress extends GeneralName
{
	/**
	 * IP address.
	 *
	 * @var string $_ip
	 */
	protected $_ip;
	
	/**
	 * Subnet mask.
	 *
	 * @var string|null $_mask
	 */
	protected $_mask;
	
	/**
	 * Get octet representation of the IP address.
	 *
	 * @return string
	 */
	abstract protected function _octets();
	
	/**
	 * Constructor
	 *
	 * @param string $ip
	 * @param string|null $mask
	 */
	public function __construct($ip, $mask = null) {
		$this->_tag = self::TAG_IP_ADDRESS;
		$this->_ip = $ip;
		$this->_mask = $mask;
	}
	
	/**
	 * Initialize from ASN.1.
	 *
	 * @param OctetString $str
	 * @throws \UnexpectedValueException
	 * @return self
	 */
	protected static function _fromASN1(OctetString $str) {
		$octets = $str->str();
		switch (strlen($octets)) {
		case 4:
		case 8:
			return IPv4Address::fromOctets($octets);
		case 16:
		case 32:
			return IPv6Address::fromOctets($octets);
		default:
			throw new \UnexpectedValueException(
				"Invalid octet length for IP address.");
		}
	}
	
	public function string() {
		return $this->_ip . isset($this->_mask) ? "/" . $this->_mask : "";
	}
	
	/**
	 * Get IP address as a string.
	 *
	 * @return string
	 */
	public function address() {
		return $this->_ip;
	}
	
	/**
	 * Get subnet mask as a string.
	 *
	 * @return string
	 */
	public function mask() {
		return $this->_mask;
	}
	
	protected function _choiceASN1() {
		return new ImplicitlyTaggedType($this->_tag, 
			new OctetString($this->_octets()));
	}
}
<commit_msg>Fix string method<commit_after><?php

namespace X509\GeneralName;

use ASN1\Type\Primitive\OctetString;
use ASN1\Type\Tagged\ImplicitlyTaggedType;


/**
 * Implements <i>iPAddress</i> CHOICE type of <i>GeneralName</i>.
 *
 * Concrete classes <code>IPv4Address</code> and <code>IPv6Address</code>
 * furthermore implement the parsing semantics.
 *
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.6
 */
abstract class IPAddress extends GeneralName
{
	/**
	 * IP address.
	 *
	 * @var string $_ip
	 */
	protected $_ip;
	
	/**
	 * Subnet mask.
	 *
	 * @var string|null $_mask
	 */
	protected $_mask;
	
	/**
	 * Get octet representation of the IP address.
	 *
	 * @return string
	 */
	abstract protected function _octets();
	
	/**
	 * Constructor
	 *
	 * @param string $ip
	 * @param string|null $mask
	 */
	public function __construct($ip, $mask = null) {
		$this->_tag = self::TAG_IP_ADDRESS;
		$this->_ip = $ip;
		$this->_mask = $mask;
	}
	
	/**
	 * Initialize from ASN.1.
	 *
	 * @param OctetString $str
	 * @throws \UnexpectedValueException
	 * @return self
	 */
	protected static function _fromASN1(OctetString $str) {
		$octets = $str->str();
		switch (strlen($octets)) {
		case 4:
		case 8:
			return IPv4Address::fromOctets($octets);
		case 16:
		case 32:
			return IPv6Address::fromOctets($octets);
		default:
			throw new \UnexpectedValueException(
				"Invalid octet length for IP address.");
		}
	}
	
	public function string() {
		return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : "");
	}
	
	/**
	 * Get IP address as a string.
	 *
	 * @return string
	 */
	public function address() {
		return $this->_ip;
	}
	
	/**
	 * Get subnet mask as a string.
	 *
	 * @return string
	 */
	public function mask() {
		return $this->_mask;
	}
	
	protected function _choiceASN1() {
		return new ImplicitlyTaggedType($this->_tag, 
			new OctetString($this->_octets()));
	}
}

{'fraction_non_alphanumeric': 0.15087347803070408, 'fraction_numerical': 0.013763896241397565, 'mean_word_length': 3.175690607734807, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '108444', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1283, 'n_words': 316}