Ejemplo n.º 1
0
        /*
         *  Rewrites post hash.
         *  Checks if post meets rules:
         *      max message size in utf-8 bytes is 65536,
         *      replyTo should be valid hash
         *  returns false if rules violated
         */
        public static bool Validate(Post p, bool bypassValidation = false)
        {
            var message = p.message.FromB64();
            var bytes   = Encoding.UTF8.GetBytes(message);

            if (bytes.Length > 65536)
            {
                return(false);
            }

            p.hash = HashCalculator.Calculate(p.replyto + message);

            if (p.replyto.Length != 32)
            {
                return(false);
            }

            foreach (var ch in p.replyto)
            {
                if (!((ch >= 'a' && ch <= 'f') || (ch >= '0' && ch <= '9')))
                {
                    return(false);
                }
            }

            var post = p.replyto + message;

            if (!captcha.Captcha.PostHasValidPOW(post) && !bypassValidation)
            {
                return(false);
            }

            if (!captcha.Captcha.PostHasSolvedCaptcha(post, bypassValidation))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 /*
  *  r - replyTo hash,
  *  m - message
  *  hash is calculated inside this constructor
  */
 public Post(string r, string m)
 {
     replyto = r;
     message = m;
     hash    = HashCalculator.Calculate(r + m.FromB64());
 }