本文整理汇总了Golang中github.com/dedis/crypto/util.Replacer类的典型用法代码示例。如果您正苦于以下问题:Golang Replacer类的具体用法?Golang Replacer怎么用?Golang Replacer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Replacer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenKey
// Generate a new public/private keypair with the given ciphersuite
// and Save it to the application's previously-loaded configuration.
func (f *File) GenKey(keys *Keys, suite abstract.Suite) (KeyPair, error) {
// Create the map if it doesn't exist
// if *keys == nil {
// *keys = make(map[string] KeyInfo)
// }
// Create a fresh public/private keypair
p := KeyPair{}
p.Gen(suite, random.Stream)
pubId := p.PubId()
// Write the private key file
secname := f.dirName + "/sec-" + pubId
r := util.Replacer{}
if err := r.Open(secname); err != nil {
return KeyPair{}, err
}
defer r.Abort()
// Write the secret key
if err := suite.Write(r.File, &p.Secret); err != nil {
return KeyPair{}, err
}
// Commit the secret key
if err := r.Commit(); err != nil {
return KeyPair{}, err
}
// Re-write the config file with the new public key
*keys = append(*keys, KeyInfo{suite.String(), pubId})
if err := f.Save(); err != nil {
return KeyPair{}, err
}
return p, nil
}
示例2: Save
// Re-save the (modified) configData loaded earlier with Load().
// Takes precautions to replace the old config file atomically
// to avoid config file corruption due to write errors or races.
func (f *File) Save() error {
// Write the new config file
filename := f.dirName + "/config"
r := util.Replacer{}
if err := r.Open(filename); err != nil {
return err
}
defer r.Abort()
// Encode the config
enc := toml.NewEncoder(r.File)
if err := enc.Encode(f.data); err != nil {
return err
}
// Commit the new config
if err := r.Commit(); err != nil {
return err
}
return nil
}