mirror of
https://github.com/saymrwulf/swisspost-evoting-go-poc.git
synced 2026-05-14 20:58:03 +00:00
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.
42 lines
984 B
Go
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"`
|
|
}
|