github.com/consensys/gnark-crypto@v0.14.0/internal/generator/crypto/hash/mimc/template/options.go.tmpl (about)

     1  import (
     2  	"github.com/consensys/gnark-crypto/ecc/{{ .Name }}/fr"
     3  )
     4  
     5  // Option defines option for altering the behavior of the MiMC hasher.
     6  // See the descriptions of functions returning instances of this type for
     7  // particular options.
     8  type Option func(*mimcConfig)
     9  
    10  type mimcConfig struct {
    11  	byteOrder fr.ByteOrder
    12  }
    13  
    14  // default options
    15  func mimcOptions(opts ...Option) mimcConfig {
    16  	// apply options
    17  	opt := mimcConfig{
    18  		byteOrder: fr.BigEndian,
    19  	}
    20  	for _, option := range opts {
    21  		option(&opt)
    22  	}
    23  	return opt
    24  }
    25  
    26  // WithByteOrder sets the byte order used to decode the input
    27  // in the Write method. Default is BigEndian.
    28  func WithByteOrder(byteOrder fr.ByteOrder) Option {
    29  	return func(opt *mimcConfig) {
    30  		opt.byteOrder = byteOrder
    31  	}
    32  }