entity_comment.go 1.63 KB
Newer Older
zauberstuhl's avatar
zauberstuhl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package federation
//
// GangGo Diaspora Federation Library
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

20 21 22 23
import (
  "encoding/xml"
  "errors"
)
zauberstuhl's avatar
zauberstuhl committed
24 25 26

type EntityComment struct {
  XMLName xml.Name `xml:"comment"`
27
  Author string `xml:"author"`
28
  CreatedAt string `xml:"created_at"`
zauberstuhl's avatar
zauberstuhl committed
29 30 31 32 33
  Guid string `xml:"guid"`
  ParentGuid string `xml:"parent_guid"`
  Text string `xml:"text"`
  AuthorSignature string `xml:"author_signature"`
  ParentAuthorSignature string `xml:"parent_author_signature"`
34 35 36 37
}

func (e *EntityComment) SignatureOrder() string {
  return "author created_at guid parent_guid text"
zauberstuhl's avatar
zauberstuhl committed
38
}
39

40
func (e *EntityComment) AppendSignature(privKey []byte, order string, typ int) error {
41 42 43 44 45 46 47 48 49 50 51 52 53 54
  signature, err := AuthorSignature(*e, order, privKey)
  if err != nil {
    return err
  }

  if AuthorSignatureType == typ {
    (*e).AuthorSignature = signature
  } else if ParentAuthorSignatureType == typ {
    (*e).ParentAuthorSignature = signature
  } else {
    return errors.New("Unsupported author signature type!")
  }
  return nil
}