github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/encoding/pem/pem.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // パッケージpemは、プライバシー拡張メールで起源を持つPEMデータのエンコーディングを実装しています。現在最も一般的なPEMエンコーディングの使用法は、TLSキーと証明書です。RFC 1421を参照してください。
     6  package pem
     7  
     8  import (
     9  	"github.com/shogo82148/std/io"
    10  )
    11  
    12  // BlockはPEMエンコードされた構造体を表します。
    13  //
    14  // エンコードされた形式は次のようになります:
    15  //
    16  // -----BEGIN Type-----
    17  // Headers
    18  // Base64エンコードされたバイト
    19  // -----END Type-----
    20  //
    21  // where [Block.Headers] is a possibly empty sequence of Key: Value lines.
    22  type Block struct {
    23  	Type    string
    24  	Headers map[string]string
    25  	Bytes   []byte
    26  }
    27  
    28  // Decodeは入力内で次のPEM形式のブロック(証明書、秘密鍵など)を見つけます。それはそのブロックと入力の残り部分を返します。PEMデータが見つからない場合は、pがnilであり、入力全体がrestとして返されます。
    29  func Decode(data []byte) (p *Block, rest []byte)
    30  
    31  // Encodeは、bのPEMエンコーディングをoutに書き込みます。
    32  func Encode(out io.Writer, b *Block) error
    33  
    34  // EncodeToMemoryはbのPEMエンコーディングを返します。
    35  //
    36  // If b has invalid headers and cannot be encoded,
    37  // EncodeToMemory returns nil. If it is important to
    38  // report details about this error case, use [Encode] instead.
    39  func EncodeToMemory(b *Block) []byte