当前位置: 首页>>代码示例>>Golang>>正文


Golang Group.Marshal方法代码示例

本文整理汇总了Golang中github.com/agl/pond/bbssig.Group.Marshal方法的典型用法代码示例。如果您正苦于以下问题:Golang Group.Marshal方法的具体用法?Golang Group.Marshal怎么用?Golang Group.Marshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/agl/pond/bbssig.Group的用法示例。


在下文中一共展示了Group.Marshal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: revocation

func (s *Server) revocation(from *[32]byte, signedRevocation *pond.SignedRevocation) *pond.Reply {
	account, ok := s.getAccount(from)
	if !ok {
		return &pond.Reply{Status: pond.Reply_NO_ACCOUNT.Enum()}
	}

	revocation, ok := new(bbssig.Revocation).Unmarshal(signedRevocation.Revocation.Revocation)
	if !ok {
		return &pond.Reply{Status: pond.Reply_CANNOT_PARSE_REVOCATION.Enum()}
	}

	// First check that the account doesn't have too many revocations
	// stored.

	revPath := account.RevocationPath()
	os.MkdirAll(revPath, 0777)

	revDir, err := os.Open(revPath)
	if err != nil {
		log.Printf("Failed to open %s: %s", revPath, err)
		return &pond.Reply{Status: pond.Reply_INTERNAL_ERROR.Enum()}
	}
	defer revDir.Close()

	ents, err := revDir.Readdir(0)
	if err != nil {
		log.Printf("Failed to read %s: %s", revDir, err)
		return &pond.Reply{Status: pond.Reply_INTERNAL_ERROR.Enum()}
	}

	if len(ents) > maxRevocations {
		// Delete the oldest revocation.
		names := make([]string, 0, len(ents))
		for _, ent := range ents {
			names = append(names, ent.Name())
		}
		sort.Strings(names)
		path := filepath.Join(revPath, names[0])
		if err := os.Remove(path); err != nil {
			log.Printf("Failed to remove %s: %s", path, err)
			return &pond.Reply{Status: pond.Reply_INTERNAL_ERROR.Enum()}
		}
	}

	path := filepath.Join(revPath, fmt.Sprintf("%08x", *signedRevocation.Revocation.Generation))
	revBytes, err := proto.Marshal(signedRevocation)
	if err != nil {
		log.Printf("Failed to serialise revocation: %s", err)
		return &pond.Reply{Status: pond.Reply_INTERNAL_ERROR.Enum()}
	}

	if err := ioutil.WriteFile(path, revBytes, 0666); err != nil {
		log.Printf("Failed to write revocation file: %s", err)
		return &pond.Reply{Status: pond.Reply_INTERNAL_ERROR.Enum()}
	}

	group := account.Group()
	if group == nil {
		return &pond.Reply{Status: pond.Reply_INTERNAL_ERROR.Enum()}
	}
	groupCopy, _ := new(bbssig.Group).Unmarshal(group.Marshal())
	groupCopy.Update(revocation)

	account.Lock()
	defer account.Unlock()

	account.group = groupCopy
	groupPath := filepath.Join(account.Path(), "group")
	if err := ioutil.WriteFile(groupPath, groupCopy.Marshal(), 0600); err != nil {
		log.Printf("failed to write group file: %s", err)
	}

	return nil
}
开发者ID:jwilkins,项目名称:pond,代码行数:74,代码来源:server.go

示例2: PackGroup

func PackGroup(out io.Writer, g *bbssig.Group) {
	var pub []byte
	pub = g.Marshal()
	basepack.Packout(out, pub)
}
开发者ID:wbl,项目名称:ringauth,代码行数:5,代码来源:obj.go


注:本文中的github.com/agl/pond/bbssig.Group.Marshal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。