swisspost-evoting-go-poc/pkg/serialize/json.go
saymrwulf e8b6f30871 Swiss Post E-Voting Go PoC
Proof-of-concept reimplementation of the Swiss Post e-voting
cryptographic protocol in Go. Single binary, 52 source files,
2 dependencies. Covers ElGamal encryption, Bayer-Groth verifiable
shuffles, zero-knowledge proofs, return codes, and a full
election ceremony demo.
2026-02-13 19:53:09 +01:00

42 lines
984 B
Go

package serialize
import (
"encoding/base64"
"encoding/json"
"math/big"
)
// BigIntJSON is a JSON-serializable big.Int (base64 encoded).
type BigIntJSON struct {
Value *big.Int
}
func (b BigIntJSON) MarshalJSON() ([]byte, error) {
if b.Value == nil {
return json.Marshal(nil)
}
encoded := base64.StdEncoding.EncodeToString(b.Value.Bytes())
return json.Marshal(encoded)
}
func (b *BigIntJSON) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
decoded, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return err
}
b.Value = new(big.Int).SetBytes(decoded)
return nil
}
// ElectionResult is a JSON-serializable election result.
type ElectionResult struct {
ElectionID string `json:"election_id"`
NumVoters int `json:"num_voters"`
NumOptions int `json:"num_options"`
Results map[string]int `json:"results"`
Verified bool `json:"verified"`
}