 #- Also, you say you think this works if resp has a byte slice (as the last
 #- item) that is larger than available in b. Have you tested that case? The docs
 #- for binary.Read seem to say otherwise.
+#**
+#** author: Tom Roeder
+#** email: tmroeder@google.com
+#** date: 2014-07-20T22:25:31-0700
+#**
+#-- Added the sanity check.
+#-- 
+#-- And I wrote a quick test case and discovered that you're right: it doesn't
+#-- work if the buffer is too big. So, I added some code and a new SliceSize
+#-- type to handle variable-length array responses from the TPM. Currently, the
+#-- only code that uses this is GetRandom, and it seems to work in my test code.
+#-- 
  
  	return nil
  }

#- Nit: Why don't you call Unpack here? Eliminates 1 line of code and
#- a variable and the need for BigEndian here.
#- if err := Unpack(outb[:rhSize], []interface{}(&rh)); err != nil { ...
 
+	// Check success before trying to read the rest of the result.
+	if rh.Tag != tagRSPCommand {

#- small, sanity check will fail. If slice is too big (which is legal according
#- to tpm spec), maybe binary.Read will fail?
#-
#**
#** author: Tom Roeder
#** email: tmroeder@google.com
#** date: 2014-07-20T22:28:49-0700
#**
#-- I think I agree about dropping the error check given the new code in
#-- Unpack. There's now no way to decode more bytes than we requested and still
#-- get to this point in the code. But b[:outSize] is still needed for the case
#-- where the TPM can't return as much randomness as requested. In that case, b
#-- will only be filled up to outSize and will have zeroes after that. So, this
#-- return statement shortens b to its proper length.
#-- 
 
-	return b, nil
+	return b[:outSize], nil
