File: //usr/local/CyberCP/lib/python3.10/site-packages/ecdsa/__pycache__/der.cpython-310.pyc
o
�h<@ � @ s d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm Z ddl
mZmZ G dd� de
�Zd d
� Zd4dd
�Zdd� Ze� Zefdd�Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd4dd�Zd d!� Zd"d#� Zd$d%� Zd&d'� Zd(d)� Z d*d+� Z!d,d-� Z"efd.d/�Z#d0d1� Z$d2d3� Z%dS )5� )�divisionN)�chain)�int2byte� text_type� )�compat26_str�str_idx_as_intc @ s e Zd ZdS )�
UnexpectedDERN)�__name__�
__module__�__qualname__� r
r
�</usr/local/CyberCP/lib/python3.10/site-packages/ecdsa/der.pyr s r c C s t d| �tt|�� | S )N� )r �
encode_length�len)�tag�valuer
r
r �encode_constructed s r �context-specificc C sh |dvrt d��| dkrt d��|dkrd}n|dkrd}n|d ks$J �d
}t|| �tt|�� | S )a-
Encode and IMPLICIT value using :term:`DER`.
:param int tag: the tag value to encode, must be between 0 an 31 inclusive
:param bytes value: the data to encode
:param str cls: the class of the tag to encode: "application",
"context-specific", or "private"
:rtype: bytes
)�applicationr �privatezinvalid tag class� zLong tags not supportedr �@ r � r � )�
ValueErrorr r r )r r �cls� tag_classr
r
r �encode_implicit s
r c C sx | dksJ �d| � � }t|�d rd| }t�|�}t|d�}|dkr.dtt|�� | S dtt|�d � d | S ) Nr �%x� � 0� � r � )�encoder �binascii� unhexlifyr r )�r�h�s�numr
r
r �encode_integer- s
r- c C s� d}d}|t u rt�dt� n5|durDd| kr dks%td�� td��|r>| s-td��t| d�}|d | d
@ r>td��t|�}d
}dtt| �| � | | S )
a�
Encode a binary string as a BIT STRING using :term:`DER` encoding.
Note, because there is no native Python object that can encode an actual
bit string, this function only accepts byte strings as the `s` argument.
The byte string is the actual bit string that will be encoded, padded
on the right (least significant bits, looking from big endian perspective)
to the first full byte. If the bit string has a bit length that is multiple
of 8, then the padding should not be included. For correct DER encoding
the padding bits MUST be set to 0.
Number of bits of padding need to be provided as the `unused` parameter.
In case they are specified as None, it means the number of unused bits
is already encoded in the string as the first byte.
The deprecated call convention specifies just the `s` parameters and
encodes the number of unused bits as first parameter (same convention
as with None).
Empty string must be encoded with `unused` specified as 0.
Future version of python-ecdsa will make specifying the `unused` argument
mandatory.
:param s: bytes to encode
:type s: bytes like object
:param unused: number of bits at the end of `s` that are unused, must be
between 0 and 7 (inclusive)
:type unused: int or None
:raises ValueError: when `unused` is too large or too small
:return: `s` encoded using DER
:rtype: bytes
� r z:Legacy call convention used, unused= needs to be specifiedN� z&unused must be integer between 0 and 7z!unused is non-zero but s is empty���r! r z unused bits must be zeros in DER� ) �_sentry�warnings�warn�DeprecationWarningr r r r r )r+ �unused�encoded_unused� len_extra�lastr
r
r �encode_bitstringB s* $��
r: c C s dt t| �� | S )N� )r r )r+ r
r
r �encode_octet_string{ � r<