Documentation
¶
Overview ¶
hash パッケージはハッシュ関数のためのインターフェースを提供します。
Example (BinaryMarshaler) ¶
package main
import (
"github.com/shogo82148/std/bytes"
"github.com/shogo82148/std/crypto/sha256"
"github.com/shogo82148/std/encoding"
"github.com/shogo82148/std/fmt"
"github.com/shogo82148/std/log"
)
func main() {
const (
input1 = "The tunneling gopher digs downwards, "
input2 = "unaware of what he will find."
)
first := sha256.New()
first.Write([]byte(input1))
marshaler, ok := first.(encoding.BinaryMarshaler)
if !ok {
log.Fatal("first does not implement encoding.BinaryMarshaler")
}
state, err := marshaler.MarshalBinary()
if err != nil {
log.Fatal("unable to marshal hash:", err)
}
second := sha256.New()
unmarshaler, ok := second.(encoding.BinaryUnmarshaler)
if !ok {
log.Fatal("second does not implement encoding.BinaryUnmarshaler")
}
if err := unmarshaler.UnmarshalBinary(state); err != nil {
log.Fatal("unable to unmarshal hash:", err)
}
first.Write([]byte(input2))
second.Write([]byte(input2))
fmt.Printf("%x\n", first.Sum(nil))
fmt.Println(bytes.Equal(first.Sum(nil), second.Sum(nil)))
}
Output: 57d51a066f3a39942649cd9a76c77e97ceab246756ff3888659e6aa5a07f4a52 true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hash ¶
type Hash interface {
// Write (via the embedded io.Writer interface) adds more data to the running hash.
// It never returns an error.
io.Writer
// Sum appends the current hash to b and returns the resulting slice.
// It does not change the underlying hash state.
Sum(b []byte) []byte
// Reset resets the Hash to its initial state.
Reset()
// Size returns the number of bytes Sum will return.
Size() int
// BlockSize returns the hash's underlying block size.
// The Write method must be able to accept any amount
// of data, but it may operate more efficiently if all writes
// are a multiple of the block size.
BlockSize() int
}
Hashはすべてのハッシュ関数で実装される共通のインターフェースです。
標準ライブラリのハッシュ実装(例:hash/crc32およびcrypto/sha256)では、 encoding.BinaryMarshalerおよびencoding.BinaryUnmarshalerインターフェースが実装されます。 ハッシュ実装をマーシャリングすると、内部状態を保存し、後で追加の処理に使用することができます。 以前にハッシュに書き込まれたデータを再度書き直すことなく、利用することができます。 ハッシュの状態には、入力の一部がそのまま含まれる場合がありますので、 ユーザーは可能なセキュリティの影響に対応することが期待されています。
互換性:ハッシュまたは暗号パッケージへの将来の変更は、 以前のバージョンでエンコードされた状態を保持することを目指します。 つまり、パッケージのリリースバージョンは、 以前のリリースバージョンで書かれたデータをデコードすることができるはずです。 ただし、セキュリティ修正などの問題により、異なる結果となる場合があります。 背景については、Goの互換性文書を参照してください:https://golang.org/doc/go1compat
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adler32はAdler-32チェックサムを実装しています。
|
Package adler32はAdler-32チェックサムを実装しています。 |
|
Package crc32は32ビットの巡回冗長検査 (CRC-32) チェックサムを実装しています。
|
Package crc32は32ビットの巡回冗長検査 (CRC-32) チェックサムを実装しています。 |
|
Package crc64は64ビットの巡回冗長検査(CRC-64)チェックサムを実装しています。
|
Package crc64は64ビットの巡回冗長検査(CRC-64)チェックサムを実装しています。 |
|
パッケージfnvは、 Glenn Fowler、Landon Curt Noll、およびPhong Voによって作成された FNV-1およびFNV-1aという非暗号化ハッシュ関数を実装しています。
|
パッケージfnvは、 Glenn Fowler、Landon Curt Noll、およびPhong Voによって作成された FNV-1およびFNV-1aという非暗号化ハッシュ関数を実装しています。 |
|
パッケージmaphashはバイト列上のハッシュ関数を提供します。
|
パッケージmaphashはバイト列上のハッシュ関数を提供します。 |
Click to show internal directories.
Click to hide internal directories.