mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-27 17:38:25 +00:00 
			
		
		
		
	* update github.com/PuerkitoBio/goquery * update github.com/alecthomas/chroma * update github.com/blevesearch/bleve/v2 * update github.com/caddyserver/certmagic * update github.com/go-enry/go-enry/v2 * update github.com/go-git/go-billy/v5 * update github.com/go-git/go-git/v5 * update github.com/go-redis/redis/v8 * update github.com/go-testfixtures/testfixtures/v3 * update github.com/jaytaylor/html2text * update github.com/json-iterator/go * update github.com/klauspost/compress * update github.com/markbates/goth * update github.com/mattn/go-isatty * update github.com/mholt/archiver/v3 * update github.com/microcosm-cc/bluemonday * update github.com/minio/minio-go/v7 * update github.com/prometheus/client_golang * update github.com/unrolled/render * update github.com/xanzy/go-gitlab * update github.com/yuin/goldmark * update github.com/yuin/goldmark-highlighting Co-authored-by: techknowlogick <techknowlogick@gitea.io>
		
			
				
	
	
		
			89 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
		
			Vendored
		
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
		
			Vendored
		
	
	
	
| // Copyright 2017 The Go Authors. All rights reserved.
 | |
| // Use of this source code is governed by a BSD-style
 | |
| // license that can be found in the LICENSE file.
 | |
| 
 | |
| package encoding
 | |
| 
 | |
| import (
 | |
| 	"io"
 | |
| 
 | |
| 	"github.com/ProtonMail/go-crypto/openpgp/errors"
 | |
| )
 | |
| 
 | |
| // OID is used to store a variable-length field with a one-octet size
 | |
| // prefix. See https://tools.ietf.org/html/rfc6637#section-9.
 | |
| type OID struct {
 | |
| 	bytes []byte
 | |
| }
 | |
| 
 | |
| const (
 | |
| 	// maxOID is the maximum number of bytes in a OID.
 | |
| 	maxOID = 254
 | |
| 	// reservedOIDLength1 and reservedOIDLength2 are OID lengths that the RFC
 | |
| 	// specifies are reserved.
 | |
| 	reservedOIDLength1 = 0
 | |
| 	reservedOIDLength2 = 0xff
 | |
| )
 | |
| 
 | |
| // NewOID returns a OID initialized with bytes.
 | |
| func NewOID(bytes []byte) *OID {
 | |
| 	switch len(bytes) {
 | |
| 	case reservedOIDLength1, reservedOIDLength2:
 | |
| 		panic("encoding: NewOID argument length is reserved")
 | |
| 	default:
 | |
| 		if len(bytes) > maxOID {
 | |
| 			panic("encoding: NewOID argment too large")
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return &OID{
 | |
| 		bytes: bytes,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // Bytes returns the decoded data.
 | |
| func (o *OID) Bytes() []byte {
 | |
| 	return o.bytes
 | |
| }
 | |
| 
 | |
| // BitLength is the size in bits of the decoded data.
 | |
| func (o *OID) BitLength() uint16 {
 | |
| 	return uint16(len(o.bytes) * 8)
 | |
| }
 | |
| 
 | |
| // EncodedBytes returns the encoded data.
 | |
| func (o *OID) EncodedBytes() []byte {
 | |
| 	return append([]byte{byte(len(o.bytes))}, o.bytes...)
 | |
| }
 | |
| 
 | |
| // EncodedLength is the size in bytes of the encoded data.
 | |
| func (o *OID) EncodedLength() uint16 {
 | |
| 	return uint16(1 + len(o.bytes))
 | |
| }
 | |
| 
 | |
| // ReadFrom reads into b the next OID from r.
 | |
| func (o *OID) ReadFrom(r io.Reader) (int64, error) {
 | |
| 	var buf [1]byte
 | |
| 	n, err := io.ReadFull(r, buf[:])
 | |
| 	if err != nil {
 | |
| 		if err == io.EOF {
 | |
| 			err = io.ErrUnexpectedEOF
 | |
| 		}
 | |
| 		return int64(n), err
 | |
| 	}
 | |
| 
 | |
| 	switch buf[0] {
 | |
| 	case reservedOIDLength1, reservedOIDLength2:
 | |
| 		return int64(n), errors.UnsupportedError("reserved for future extensions")
 | |
| 	}
 | |
| 
 | |
| 	o.bytes = make([]byte, buf[0])
 | |
| 
 | |
| 	nn, err := io.ReadFull(r, o.bytes)
 | |
| 	if err == io.EOF {
 | |
| 		err = io.ErrUnexpectedEOF
 | |
| 	}
 | |
| 
 | |
| 	return int64(n) + int64(nn), err
 | |
| }
 |